How to add search help to selection parameter?

 

I was looking for help to add search help in selection parameter. But I didn’t find any simple one to understand. So I am going to explain for the beginner how to add search help in selection parameter.

DATA:  it_return TYPE STANDARD TABLE OF ddshretval,
wa_return LIKE LINE OF it_return.
PARAMETERS: p_traid TYPE likp-traid.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_traid.

*-->; Now call FM F4IF_FIELD_VALUE_REQUEST

CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
EXPORTING
tabname = 'likp'
fieldname = 'TRAID'
searchhelp = 'ZTRAID'
TABLES
return_tab = it_return[]
EXCEPTIONS
field_not_found = 1
no_help_for_field = 2
inconsistent_help = 3
no_values_found = 4
OTHERS = 5 .
IF sy-subrc <;> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

*-->; Read it_return table data and assign to the parameter.

IF sy-subrc EQ 0.
READ TABLE it_return INTO wa_return INDEX 1.
p_traid = wa_return-fieldval.
ENDIF.

 

image

image

Advertisements

SAP Set Types

Introduction – Set Types and Attributes

Set Types and Attributes: Set Types are the group of different attributes which are assigned to Product/Material and are available on Product Page in CRM System. These Set Types are stored in system as a table which contains records.

Set Types and Attributes are used together with Product Hierarchy and Categories created.

A correct combination of set types with its hierarchy & category allows it to get displayed on Product page ‘COMMPR01’.

Product Hierarchy: Product Hierarchy is mainly used to structure all the Product related data, this Hierarchy depends on individual Organization requirement and process.

This Product Hierarchy consists of Product Category which is useful for categorization of Product.

Categories are assigned to Hierarchy and one Hierarchy can contain multiple categories at different level e.g. Parent and Sub category.

These Sub Categories can contain multiple Set Types with different attributes assigned to them.

For above relationships refer Figure 0:

clip_image002

Figure 0 – Set Type Relationship

COMM_ATTRSET” is the Transaction Code for creating Attribute and Set Type in SAP CRM system.

Set Types can be created only for Material/Product objects in CRM system and not for any other Objects. Set Types are customized attributes of Object Material/Product in addition to the standard attributes.

Following Figure 1 shows Set Type name “ZWATCH_SET_TYP” and Attribute name as “ZWATCH_MODELS”.

Step 1: Create Attribute

Launch the T-Code “COMM_ATTRSET” to Create Attribute.

clip_image003

Figure 1 – Creating Attribute

Attributes basically contains of two tabs, one for Definition and other for Value Range. Definition defines the characteristics of the attribute and Value Range provides option for fixed range values. Definition and Value Range are shown in Figure 2 and 3 respectively.

clip_image004

Figure 2 – Defining Characteristics

Refer to Attribute “ZWATCH_MODELS” in Figure 3 for value range.

clip_image006

Figure 3 – Assigning Values

Step 2: Create Set Type

The Set types can be created as shown in Figure 4, the assignment of attributes to the created set type is discussed further. Refer Figure 4 for creation of Set Type.

clip_image007

Figure 4 – Creating Set Type

The Set Type creation requires defining the set type and assigning attributes to it. The definition part contains option for ‘Product type selection’ and other details related to characteristics, refer Figure 5.

clip_image009

Figure 5 – Defining Set Type Characteristics

Definition of single or multiple values can be done with check “Multiple Values Possible” option. With the above option checked each record of a set type is assigned indirectly to a product using an assignment table.

clip_image010

Figure 6 – Defining Set Type Characteristics

clip_image011

Figure 7 – Multiple value attribute

Now created Attribute needs to be assigned to Set Type, refer Figure 8.

clip_image013

Figure 8 – Assigning Attribute

The steps so far showed the process to create attribute and then create a set type with reference to the attribute. The next part of the document discusses about hierarchy and how set type can be attached to screens so that users can access it.

Step 3: Create Hierarchy

In its basic form hierarchy is used to maintain the products or the object within certain criteria for differentiation. This configuration depends on individual organizations process flow.

Hierarchy can have multiple levels depending upon the information flow for any product or Object.

COMM_HIERARCHY” is Transaction code to create Hierarchy, refer Figure 9.

clip_image014

Figure 9 – Creating Hierarchy

When New Hierarchy button is clicked, Hierarchy ID and its descriptions are entered, refer Figure 10.

clip_image016

Figure 10 – Defining Hierarchy ID

When Hierarchy is created (by pressing OK button), the following screen insists for category creation. Categories, similar to hierarchy groups products and individual objects based on different criteria.

These Categories are arranged in Hierarchy, and Set Types are arranged in Categories.

These Categories can also have multiple level for Example one Root Category is mandatory and inside that Root Category there are multiple child categories.

The information shown in below Figure 11, Figure 12 and Figure 13 contains a hierarchical structure,

The reason why this has been created is to allow for flexibility in defining products.

Step 4: Create New Category

clip_image017

Figure 11 – Creating Root Category

clip_image018

Figure 12 – Setting Product Type for Category

Creating Child Category “ZW02” under Root Category “WAT_R_CAT”, refer Figure 13

Step 5: Create New Sub Category

clip_image019

Figure 13 – Creating Sub Category

When creating sub-category we need to set the Product Type as Material, refer Figure 14

clip_image020

Figure 14 – Created Sub Category

Now we have got one hierarchy “ZWATCH_HY” within which we have got one Root Category “WAT_R_CAT” and again within this Category we have got another sub-category with name “ZW02”.

· ZWATCH_HY : HIERARCHY NAME

· WAT_R_CAT : ROOT CATEGORY NAME

· ZW02 : SUB-CATEGORY NAME

Step 6: Assign Set Types to Category

To assign Set Type to a particular Category refer Figure 15.

clip_image022

Figure 15 – Adding & Assigning Set Type to Sub-Category

After assigning Set Types to a Category, refer Figure 16, Along with this we need to set two attributes Position and View-ID of that Set Type.

Both of these parameters are used to configure the availability of this Set Type in Product Master. In Our Example we have set Position = 0 and View ID = Basic (Figure 16 and Figure 17), so according to this configuration, newly added Set Type will get displayed at Position 0 in General Tab, refer Figure 18.

clip_image024

Figure 16 – Setting Position and View-ID

clip_image026

Figure 17 – Position and View-ID

clip_image028

Figure 18

In Figure 17 we have assigned our created Set Type to Category “ZW02”. Now we are all set to use this Set Type in our Product/Material screen.

To use this Set Type in Product/Material Screen we need to move to another Transaction Code “COMMPR01” to open Product/Material Details, refer Figure 19.

clip_image030

Figure 19 – Adding Sub Category to Product Page

Here we need to add our Set Type (T-Code “COMMPR01”). Click on SAP Basic Data Tab and then click on Edit button so that changes to the screen data are made.

Now when the Screen is open to edit, enter the Category in SAP Basic Data tab and press Enter, rest of the information about that Category will automatically be populated, refer Figure 19. This information will contain the Hierarchy ID and Category Description.

When once all information is entered, the document can be saved. Now, when transaction code “COMMPR01” is executed the Set Types can be seen under general tab, refer Figure 20.

clip_image032

Figure 20 – Displayed Set Type on Product Page

Above Figure 20 shows the value range that we have defined while creating Set Type, this value range will be available as F4 Help along with Set Type. For table and field details refer Figure 21.

clip_image034

Figure 21 – Set Type Table and Field name

All information that will be saved through this Set Type will be stored in table “ZWATCH_SET_TYP” this table name is same as that of Set Type name, having one field “ZZ0010” which will actually store this value shown, refer Figure 22

clip_image036

Figure 22 – Set Type Table with Saved Information

While creating a Set Type one table gets generated automatically (“ZWATCH_SET_TYP”) which stores the Set Types value, refer Figure 23

clip_image038

Figure 23 – Set Type Table Structure (Fields)

Step 1: Code Demo

The steps/processes so far discussed (creation of Attributes, Set Types, Hierarchy, Category and finally Sub Category) were from functional aspect.

After that we have to assign this Category to Products using T-Code “COMMPR01” (Product master workbench).

The following section provides technical information on how to update set types trough ABAP.

Example

Function Module “Z_UPDATE_EXT_AB” which explains how to update information in Set Type programmatically.

Figure 24 shows the Set Type under Transaction “COMMPR01” (Product master workbench).

clip_image039

Figure 24 – Code Example Set Type

clip_image041

Figure 24 – Code Example Set Type Table & Fields

Above Figure 24 shows Set Type “ZKEYWORD_EX_AB” which is used to demonstrate the ABAP code example.

Report Program to update value of Set Type

FUNCTION Z_UPDATE_EXT_AB.
*"----------------------------------------------------------------------
*"
*"Local Interface:
*"
IMPORTING
*" REFERENCE(L_PRODUCT_ID) TYPE COMT_PRODUCT_GUID
*"
REFERENCE(L_PROD_DESC) TYPE CHAR_50
*"----------------------------------------------------------------------
CONSTANTS:
abap_true TYPE sap_bool VALUE 'X',
lc_ptype TYPE char2 VALUE '01'.

DATA: lt_bapireturn TYPE bapiret2_tab, "
For Error Messages
ls_bapireturn TYPE bapiret2, "For Error Messages
ls_product TYPE comt_product, "
Product Information
lv_logsys TYPE comt_logsys. "Logical system Name



DATA: lt_product TYPE comt_product_maintain_api_extt,
ls_prod_chg TYPE comt_product_maintain_api_ext,

lt_set TYPE comt_product_maintain_api_sett,
ls_set TYPE comt_product_maintain_api_set,

lt_key TYPE REF TO zkeyword_maintain_abt,
ls_key TYPE zkeyword_maintain_ab.

ls_product-product_type = lc_ptype. "
Passing Product Type
ls_product-product_guid = l_product_id. "Passing Product GUID
ls_prod_chg-header-com_product = ls_product.

ls_set-settype_id = 'ZKEYWORD_EX_AB'. "
This is SetType Name
ls_key-data-logsys = 'BC1CLNT100'. "This is Logical system
CREATE DATA lt_key.
ls_key-data_x-zz0010 = abap_true. "
Need to pass abap_true
ls_key-data-zz0010 = l_prod_desc.
APPEND ls_key TO lt_key->;*.

ls_set-data = lt_key.
APPEND ls_set TO ls_prod_chg-data.

CLEAR ls_set.
APPEND ls_prod_chg TO lt_product.


CALL FUNCTION 'COM_PRODUCT_MAINTAIN_MULT_API'
IMPORTING
et_bapireturn = lt_bapireturn
CHANGING
ct_product = lt_product
.
IF sy-subrc <;> 0.
ENDIF.

CALL FUNCTION 'COM_PRODUCT_SAVE_API'
EXCEPTIONS
OTHERS = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = ls_bapireturn.

ENDFUNCTION.

 

Join:

www.imhere4.com

Enhancement Framework – BADI

The new Enhancement Framework and Kernel BADI

The BADI is an object-oriented enhancement option. The BADI defines an interface that can be implemented by BADI-implementations that are transport objects of their own. The new BADI is fully integrated into the Enhancement Framework.

BAdis are like predefined Enhancement options available in SAP which can then be Implemented by the Industries as per there needs.

BAdis: Business Add Ins are Enhancements to the standard SAP code. These BAdi Enhancement can be done with the Interfaces which contains various methods (standard or customized). This Interface name is generated automatically and can be changed as required.

After defining the Interfaces developer assign some methods as required to these interfaces. These methods can have only Importing and Changing parameters Exporting Parameters are not allowed. Finally BAdi is Activated and ready to be used in program.

For creating BAdi first we need to create Enhancement Spot. New BAdi can only be created inside SPOT.

Below figure shows how to create Enhancement SPOT (TCode-SE18)

clip_image002

clip_image004

 

1

New Enhancement SPOT is created.

Now we are creating new BAdi inside this created Enhancement SPOT

Click on Create BADI button.

clip_image008

Provide BAdi name and short description.

clip_image010

BAdi requires one Interface which will contains all methods.

Creating new Interface, just doule click on Interface link under the BAdi definition section.

clip_image012

Provide the Interface name to be created.

clip_image014

 

1

clip_image018

As soon as you will save Interface, it will open new screen to define methods inside this Interface.

All these methods can then be called using BAdi.

clip_image020

Create two different methods namely Addition and Subtraction and provide the parameter list for these methods created inside Interfaces.

clip_image022

The parameters inside these Interface methods can only be Importing and Changing. Exporting parameters are not allowed in Interface methods.

clip_image024

Two created methods are displayed inside Interfaces.

clip_image026

Two steps are already completed

  1. Created new BAdi
  2. Created Interface and added two methods as required.

 

Now need to create Enhancement Implementation so that methods created inside Interfaces can be called.

clip_image028

Enhancement Implementation required Class name.

clip_image030

Class name is required here because using this class only we will be able to use ethods.

clip_image032

A new BADI implementation will be created with name “Z_BADI_IMPL”.

clip_image034

Double click on Implementing Class then following screen with two Interface methods will get displayed.

clip_image036

Double click on any Interface method. Currently these methods are all blank and need to Implement to have custom logic inside these methods.

clip_image038

clip_image040

clip_image042

Now to use this we have created new Report Program

clip_image044

ABAP statements GET BADI, CALL BADI are used to Access Badi Objects.

Filters:

Filters are mainly used as a condition to switch over different implementations methods. For example there is one BAdi having Implementation for converting any amount to UD. Now there is one more new requirement to have currency conversion to IN.

In this case we need to have different Implementation in BAdi which will be switched based on the input provided by the user. This calling of Implementation is all dynamic and can only be determined by BAdi at runtime.

Now creating filters in BADI

clip_image046

clip_image048

clip_image050

Click on Activate.

Now Double click on Enhancement Implementation to open it.

clip_image052

Double Click on Filter and then click on EDIT button.

After this to add different Filter condition click on Combination button.

Now time to add filter condition in created Filters.

clip_image054

When click on Combination button following screen will be displayed.

Here double click on “????” to add new filter conditions.

clip_image056

Need to place value for these filters which will be used by BAdi to decide at runtime which method to call.

In our example we are making calculation based on Country so I have taken IN (India) and another filter will be US.

clip_image058

Two filters are created.

clip_image060

Activate the BADI.

Now to play with Filters we need to create another Implementation which will get called based on Country selected by User.

Need to create another Implementation which will calculate the result based on US country.

1

Every Implementation needs a class, if we provide same class name then this Implementation will inherit the methods of first Implementation which will be useless.

clip_image064

Now we have two Enhancement Implementations, having different method implementations one for US and another for IN.

clip_image066

Double click on Enhancement

clip_image068

Now create new filter for this Implementation

clip_image070

For US we have added 100 more to both parameters.

clip_image072

Now filters are all ready to be used in Report program.

clip_image074

In above screen shot highlighted section shows how to use filters in program.

Source Code:

REPORT z_badi_calc_ab.

PARAMETERS : pctry TYPE land1,

paramet1 TYPE i,

paramet2 TYPE i.

DATA : resultadd TYPE i,

resultsub TYPE i,

objbadi TYPE REF TO z_badi_calc_ab. "Creating object to call BADI's implemented methods

GET BADI objbadi

FILTERS

z_country_filter = pctry. "
Passing Filter values.

CALL BADI objbadi->;;addition

EXPORTING

param1 = paramet1

param2 = paramet2

CHANGING

RESULT = resultadd.


WRITE: / 'Add Result: ', resultadd.

CALL BADI objbadi->;;substraction

EXPORTING

param1 = paramet1

param2 = paramet2

CHANGING

RESULT = resultsub.

WRITE: / 'Substraction Result: ', resultsub.

 

This is how we can implement BAdis.

SAP Enhancement Framework

 image

This New Enhancement frame work provides all new enhancement technologies such as new business add-ins ( BAdIs ) and source code plug-ins.

Kernel BADIs

New BADIs are also Known as Kernel BADIs , These BADIs are object-oriented enhancement options (or plug-ins). These BAdIs are based on interfaces that may be implemented by classes that may then be transported.

You can see Kernel BADIs from the transaction code Se18:

(Note :Technically badis are link with the Enhancement Spot)

 Source code plug-ins

In Source code plug-ins we have many options like Explicit Enhancement and Implicit Enhancement Developers (both SAP and non-SAP) may provide special hooks or portions in their code where enhancements may be applied. These are known as explicit enhancement options, and are mostly created by SAP at specific points of standard programs.

Explicit Enhancement:

In simple word explicit enhancement is provided by SAP, It is predefined location or plugs where you can put your code and enhance the standard. To see the explicit enhancement options in the object it requires to click on the spiral button (shown in yellow color and blue border in below image) which is given in the top tool bar.

 image

Supported Enhancement Technologies

The Enhancement Framework supports a number of different enhancement technologies, including:

• Class Enhancements. Class enhancement lets you add new methods to a class. Moreover, you may also

add optional parameters to existing methods.

• Function Group Enhancements. You may add new parameters to a function module via function group

enhancements.

• Source Code Enhancements. These may be enhancement points in the source code where source

code plug-ins may be attached. These plug-ins contain the code that enhances the given program, and

are treated as an addition to the original code of the program in question. On the other hand, the code

with the enhancement section may be substituted with the source code plug-in code used.

This plug-ins in the source code is called as Enhancement SPOTS.

SPOTS can be categorized in :

  1. Enhancement POINTS
  2. Enhancement SECTION

In simple words When you want to add your extra logic over the existing one use POINTS while when you want to replace the existing one use SECTION. When a SPOT is static it is used for data declaration while Dynamic SPOTS are used for coding.

Enhancement POINTS and SECTION are looks like as mentioned Below:

ENHANCEMENT-POINT <name> SPOTS <spot1> [<spot2>] [STATIC] …

ENHANCEMENT-SECTION <name> SPOTS <spot1> [<spot2>] [STATIC] END-ENHANCEMENT-SECTION.

Implicit Enhancement:

In last if nothing works , like you don’t have any Explicit enhancement or you don’t have any BADIs, Do implicit enhancement .

This is easiest enhancement you can ever find.

Implicit enhancement options are provided internally in the beginning and end of every subroutine , Function module and methods. Where you can put your own code. Check the article

Switch Frame Work:

Each Enhancement package contains a set of business functions. Each “business function” are optionally implemented and activated. Switch frame work is something using which you can deactivate certain Business functionality depending on the client requirement. You can also assign switch to your implemented enhancements so if required you can de activate all of them in single go.

Code Example of Explicit and Implicit Enhancement :

image

CMOD and SMOD:

CMOD and SMOD is another Enhancement technique.

CMOD is the Project Management of SAP Enhancements (i.e., SMOD Enhancements). SMOD contains the actual enhancements and CMOD is the grouping of those SMOD enhancements. 

Enhancements are exits developed by SAP. The exit is implemented as a call to a function module. The code for the function module is written by the developer. You are not writing the code directly in the function module, but in the include that is implemented in the function module. 

Read JSON using JavaScript

Hi Guys,

Here we are going to have a simple code which will show how to read data from JSON and fill Dropdown. All will be done through JavaScript.

Very first thing we are going to make one JSON object with Weather Information city wise.

After that we have made some functions which will be used to fill the dropdown list for City and Weather.

<script language="javascript" type="text/javascript">

var objJSON = { "weatherdetails":
    {
        "weatherreport":
            [
                {"city": "Mumbai", "weather": "32" },
                {"city": "Delhi", "weather": "28" },
                {"city": "Chennai", "weather": "34" },
                {"city": "Kolkata", "weather": "26" }
            ]
    }
};

var obj = eval(objJSON.weatherdetails);

function showJSON(){
    for(var i=0;i<obj.weatherreport.length;i++){
    alert(obj.weatherreport[i].city + "----" + obj.weatherreport[i].weather);
    }
}

function LoadCity(){
    var optionCity = "Select One City";
    document.getElementById("ddlCity").options[0] = new Option(optionCity, "0");
    for(var i=0;i<obj.weatherreport.length;i++){
        document.getElementById("ddlCity").options[i+1] = new Option(obj.weatherreport[i].city, obj.weatherreport[i].city);
    }

}

function LoadWeather(){

    var optionWeather = "Select One Weather";
    document.getElementById("ddlWeather").options[0] = new Option(optionWeather, "0");
    for(var i=0;i<obj.weatherreport.length;i++){
        document.getElementById("ddlWeather").options[i+1] = new Option(obj.weatherreport[i].weather, obj.weatherreport[i].city);
    }
}

function showWeather(ctrl){
    var strCity = ctrl.options[ctrl.selectedIndex].value;
    var strWeather = document.getElementById("ddlWeather");
    for(var i = 0; i < strWeather.length; i++)
       {
        if(strWeather.options[i].value == strCity){
                  strWeather.selectedIndex = i;
            return;
        }

       }
}

</script>

 

Below is the HTML code:

<div>
       <input type="button" id="btnShow" value="Show City and Weather" onclick="showJSON();" /></div>
<div>
       <input type="button" id="btnLoadCity" value="Load City" onclick="LoadCity();" />
       <select id="ddlCity" onChange="showWeather(this);"></select>
<div id="dvCity"></div>
</div>
<div>
        <input type="button" id="btnLoadWeather" value="Load Weather" onclick="LoadWeather();" />
        <select id="ddlWeather"></select>
</div>

 

Below is the code which used to load the dropdown list on onload function.

<script language="javascript" type="text/javascript">
function loadData(){
    LoadCity();LoadWeather();
}

window.onload = loadData;
</script>

 

This is final output of above code :

JSON

How to post Data using JQuery..

Guys,

I have Implemented JQuery’s “$.post” method so thought this can be helpful for someone..

putcomments1

This is how our application look like. Once we put our comments in box and press Quick Comments button it will call JQuery $.post method to post User entered data to Server and will save it in DB table.

So here are the steps to make a comment posting code :

First we need to include JQuery files (Update Script file path according to your directory structure):

<script src=”Scripts/jquery-1.4.1.min.js” type=”text/javascript”></script>
<script src=”Scripts/jquery-1.4.1-vsdoc.js” type=”text/javascript”></script>
<script src=”Scripts/jquery-1.4.1.js” type=”text/javascript”></script>

Following is the HTML code which will give you above output (Ofcourse this is not full code with css and all)

<div>
                        <%   1: # DataBinder.Eval(Container.DataItem, "Postcontent")
%>
                        <br />
                        <div align="left">
                            <a href="#" class="comment_button" accessid='<%# DataBinder.Eval(Container.DataItem, "Postid") %>'
                                id='btnComment_<%# DataBinder.Eval(Container.DataItem, "Postid") %>'>Quick comment</a>
                        </div>
                        <div class='panel' id='slidepanel<%# DataBinder.Eval(Container.DataItem, "Postid") %>'>
                            <textarea cols="50" rows="2" id='txtComment_<%# DataBinder.Eval(Container.DataItem, "Postid") %>'></textarea><br />
                            <input type="button" value=" Quick comment " accessid='<%# DataBinder.Eval(Container.DataItem, "Postid") %>'
                                id='btnCommentSubmit_<%# DataBinder.Eval(Container.DataItem, "Postid") %>' class="comment_submit" />
                        </div>
                        <div id='postedComment_<%# DataBinder.Eval(Container.DataItem, "Postid") %>'>
                        </div>
                    </div>

 

Now time to write some code on Quick Comment button which actually saves the data into database. So following is the JQuery code which will do this task for us.
$(document).ready(function(){
        $(function () {
            $('.comment_submit').click(function () {
                if (isUserLoggedIn == "True" || isUserLoggedIn == "true") {

                    var element = $(this);
                    var id = element.attr("accessid");
                    var commentText = $('#txtComment_' + id).val();
                    if (commentText == "") {
                        showNotification({
                            message: "Please put some comments to post.",
                            type: "error",
                            autoClose: true,
                            duration: 3
                            });
                     return false; }
                    $.post(
                    'Global/AjaxRequestData.aspx',
                    { mode: "comment", comment: commentText, Commentpostid: id },
                    function (data) {
                        var retVal1 = $('#lblMessage', data).html();
                        var retVal2 = $('#lblReturnValue', data).html();
                        var $readcmnt = $('#btnViewComment_' + id);
                        if (retVal1 == "1") {
                            //$('#postedComment_' + id).addClass("success");
                            //$('#postedComment_' + id).html("Comment posted successfully. You can see more comments by clicking on <b>Read comments</b> link.").show();
                            /*$('.dvUserAlerts').slideDown('slow', function(){
                                $('.dvUserAlerts').html("Comment posted successfully. You can see more comments by clicking on <b>Read comments</b> link.");
                            });*/

                            showNotification({
                            message: "Comment posted successfully. You can see more comments by clicking on <b>Read comments</b> link.",
                            type: "success",
                            autoClose: true,
                            duration: 3
                            });

                            /*$readcmnt.stop();
                            $readcmnt.css("background-color", "red");
                            $readcmnt.css("color", "white");*/
                        } else {

                        showNotification({
                            message: "Some problem in posting your comments please try after some time.",
                            type: "error",
                            autoClose: true,
                            duration: 3
                            });

                            /*$('#postedComment_' + id).addClass("error");
                            $('#postedComment_' + id).html("Some problem in posting your comments please try after some time.").show();*/

                        }
                        $("#slidepanel" + id).slideUp(300);
                        /*$('#postedComment_' + id).delay(10000).slideUp(1400);*/
                        $('#txtComment_' + id).val("");
                    }
                    );
                    //$('#postedComment_' + id).load('global/popup.aspx');
                } else {

                    $('#dvReadComments').load('global/popup.aspx?mode=login');
                    ShowModalPopup('dvComments'); return false;
                        //showLogin();
                }
            });
        });
        });

 

You will notice in above code there is one function I have called with name “showNotification” this is one my custom made JS function which shows the alert messages, although you can also use simple Javascript alert for the same.

Sorry : I have not actually removed some commented code.. 🙂

In above code main part is call to another aspx page which actually contains the code logic of saving this comment. Along with this “post” request we are also passing some parameters named as mode, comment, commentText, Commentpostid which will carry respective values.

$.post(
          'Global/AjaxRequestData.aspx',
          { mode: "comment", comment: commentText, Commentpostid: id },

 

The above used “AjaxRequestData.aspx’” page will contain some normal conditions as shown in below code, as we have send our parameters through POST method we need to catch these parameters with “Request” Object also shown in below code. Here your actual saving code logic will come which will save your data..

This “AjaxRequestData.aspx’” page will also contains some HTML code which contains some elements used to actually catch the response from server.

<pre>
            <asp:Label ID="lblMessage" runat="server" Style="display: none"></asp:Label>
            <asp:Label ID="lblReturnValue" runat="server" Style="display: none" EnableViewState="false"
                Text=""></asp:Label>
 </pre>
if (Request["mode"] != null && Request["mode"] == "comment")
{
    string Commenttext = Request["comment"].ToString();

    lblMessage.Text = "Your Save Function will come here return some values (0 or 1)"
    lblReturnValue.Text = lblMessage.Text;
 }

 

 

So Guys this was all code through which you can make a comment posting control using JQuery.

Hope this will help you out 🙂

Please do let me know If you need any clarification on this code.

Finally I have installed Windows Live Writer

This is really good to have Windows Live Writer and now I can post more frequently …

Installation Steps

  • For installation of Live Writer make sure you have the following system requirements. More important that it requires a .Net Framework.
  • Download the Live Tools Installer. This installer is not the Live Writer Installer. Instead it is general purpose installer and lets you select more products to install if needed.
  • Start the installation from WLinstaller.exe
  • Accept the agreement policy.
  • Uncheck all the check boxes. They are optional utilities.
  • The installer then downloads the Live Writer installation. Please be patient as it takes quite a lot of time if you have slow connection.
  • You don’t have to do check anything. The installation would immediately after the download is complete.
  • Follow the further steps which include putting the login credentials, blog URL.
  • Allow the installation to detect the blog layout settings and post a temporary post to verify. It won’t affect your blog since no test post is published.
  • Start the Writer and blast away with your writing. Enjoy!

Live Writer makes you feel as if you are working in the WordPress environment itself. Blogging with it will surely enthral you. Try it out and you will see the difference for yourself.

live1_thumb

live2_thumb

live3_thumb

And finally you are ready to post 🙂

 

WLR

Building Multilingual Application

Multilingual applications are those which which supports the different Language for customers of different counties.

The most important thing to develope the ML Application is Resource file, which contains all the ML Data such as the text which is to be displayed on the form (in different languages).

These resource files can be the file with “resx” extension or may be with “txt” extensions.
Suppose we want to generate one resource file for Hindi Language one for Franch Language and soon.

These files will be named as follows :
Hindi Language : Resource.HI.txt
French Language : Resource.FR.txt
…..
…..

We know that the Satellite Assembely id needed to make Multilingual Application.
So we will use “Resgen.exe” comand to generate Satellite Assembely, that can be done as follows :

resgen C:\Resource.HI.txt
resgen C:\Resource.FR.txt

These two commands will generate the Satellite Assembely for these resource files with following names :

Resource.HI.resources
Resource.FR.resources

These generated resource files we will put in a folder named “Resources”.
With this we have completed our first round of work.. 🙂
We will build this application and this will generate two new folders in “Bin” directory with the name “FR” and “HI”.

Along with this we need to place these two files in Resource Folder inside Bin.

Now we have done with the Satellite Assembely generation part, now all we need to do is use these Satellite Assembely in our code by reading content from it.

For this we will create one class and place following code in that to read the Resource content.

This HI resource file contains :

 

In this file we need to place different Namespaces :

This is the main code which will read the Resource file.

Now we will write the code to call this function on some button…

This above function we can call on any control say on Button Click…
And we are done with the Localisation… 🙂

 

 

SqlServer 2008 new features

Below are some of the SqlServer 2008 new features :

1) Inline variable assignment :
Instead of:
DECLARE @myVar int
SET @myVar = 5

you can do it in one line:
DECLARE @myVar int = 5

2) C# like syntax:
SET @i += 5

3) Auditing :
Sql Server2008 Auditing feature is a superb feature to audit ur changes later, for this SqlServer2008 introduced the automatic auditing feature.

4) Processing of delimited strings:
This is awesome and I have used this feature.
Currently, we pass in delimited strings in the following manner:

exec sp_demoProc ‘Rohit,35;Mayank,31;Rider,27;Lakhan,42’

In 2008, Microsoft introduced Table Value Parameters (TVP).

CREATE TYPE PeepsType AS TABLE (Name varchar(20), Age int)
DECLARE @myPeeps PeepsType
INSERT @myString SELECT ‘Rohit’, 35
INSERT @myString SELECT ‘Mayank’, 31
INSERT @myString SELECT ‘Rider’, 27
INSERT @myString SELECT ‘Lakhan’, 42

exec sp_MySproc2 @myString

5) Intellisense :
This is another great feature of SqlServer2008, now user gets the Intellisense while writing the SPs and Queries just like we get in .Net.

Returning a ViewModel in MVC

Some time it happes when we want to display certain Information in form according to some ID.
This form may contain some Dropdown fields some textboxes or may be other web controls, these controls should display
proper information according to to that ID.
So Instead of writing this code on the Controller class (making controller massy 😦 ) or a smart way could be
creating a ViewModelClass and retutn it.

What a ViewModelClass contains is all the methods and functions which are required to fill all controls according to ID.

Suppose I have a view contains different Dropdowns and textboxes.
I will create a ViewModelClass for this as below :

 public class AddEditScheduleViewModel
    {
        #region Public Properties
        public SelectList ddlClient { get;  set; }
        public SelectList ddlStaff { get;  set; }
        public string txtScheduleDate { get;  set; }
        #endregion 

        #region Contructor
        public AddEditScheduleViewModel()
        {
            ddlClient = new SelectList(ClientsDAL.GetClientList(SessionHandler.LoggedinUserInfo.AgencyID, "02"), "clientID", "entDisplayName");
            ddlStaff = new SelectList(StaffDAL.GetStaffList(SessionHandler.LoggedinUserInfo.AgencyID), "staffID", "staffName");
            txtScheduleDate = DateTime.Now.ToShortDateString();
        }
	#endregion 
     }

Here we have made one Constructor “AddEditScheduleViewModel()” where we have written code to get data for dropdown.

<%=Html.DropDownList("ddlClient",(SelectList)ViewData["ddlClient"], "", new { onChange="return onClientChange(this)" , @Style = "width:65%" })%>
<%=Html.DropDownList("ddlStaff",(SelectList)ViewData["ddlStaff"], "", new { onChange="return onStaffChange(this)", @Style = "width:65%" })%>

This ViewModel may also contains some method Overloads like below :

public AddEditScheduleViewModel(string ScheduleID)
{
    getSchedulDataByID(ScheduleID, "none");
}
public AddEditScheduleViewModel(string ScheduleID,string mode)
{
    getSchedulDataByID(ScheduleID,mode);
}

Now how to use this ViewModelClass and how to call these Overload methods :

public ActionResult AddEditSchedule(string Submit) { 
switch (Submit)
    {
	case "Save":
		AddSchedule(ScheduleID); //Add Edit Schedule Event
		return View(new AddEditScheduleViewModel());
	case "Delete":
		DeleteSchedule(ScheduleID);
		return View(new AddEditScheduleViewModel());
	case "Show Conflict":
		return View(new AddEditScheduleViewModel(Request.Form["hdnConflictSchedID"].ToString()));
	default:
	    //your custom code will go here
    }
}