CA Service Management

 View Only
Expand all | Collapse all

how to get the read only field value to the java script function

venkateswarlu v

venkateswarlu vOct 27, 2017 06:03 AM

  • 1.  how to get the read only field value to the java script function

    Posted Oct 24, 2017 01:01 PM

    I'm trying to get the read-only field value to the javascript function tried different options but nothing seems to be working.

    please let me know if there is a better approach.

     

     

    Edit mode

     

    DOM Structure

     

    <td id="df_0_6" pdmqa="risk" style="font-size:0.7em;" class="detailro" align="left" valign="top">
    Major
    </td>

     

     I'm trying to fetch the risk value on 'onblur' event in edit mode of the detail page.

    The code that I'm using is the below

     

    jq('input[pdmqa="risk"]').text()
    jq('input[pdmqa="risk"]').html()
    jq('input[pdmqa="risk"]').val()

    however the all calls returned  'empty'  value. how to get the risky value?

     

    Thanks

    Venkat



  • 2.  Re: how to get the read only field value to the java script function

    Broadcom Employee
    Posted Oct 24, 2017 03:08 PM

    you may try

    document.main_form.elements["SET.risk"].value



  • 3.  Re: how to get the read only field value to the java script function

    Posted Oct 24, 2017 03:25 PM

    Hello,

     

    Tried and the return type is undefined, there is no variable with the name SET.risk

     

    Thanks



  • 4.  Re: how to get the read only field value to the java script function

    Posted Oct 24, 2017 03:56 PM

    Just tried with the below syntax and It returns the risk value

     

    console.log(jq("td[pdmqa='risk']").text());



  • 5.  Re: how to get the read only field value to the java script function

    Broadcom Employee
    Posted Oct 24, 2017 04:26 PM

    you used console.log?

    if you look at the out of box htmpl files you can see how the attribute values are refereed in the js script



  • 6.  Re: how to get the read only field value to the java script function

    Posted Oct 25, 2017 06:21 AM

    Hi.

    instead of going to the DOM, why not using the webengine directly to get this value?

    maybe this one helps:

     

    var risk_level_sym="$args.risk.sym";

     

    Hope this helps

    ..........Michael



  • 7.  Re: how to get the read only field value to the java script function

    Posted Oct 25, 2017 08:12 AM

    Thank you for the response.

    Only reason I'm going to DOM is that to get the current selected value before save, for some roles the Risk form field is open for selection.

     

    I have another query,  the scenario is like this, 

    The ticket is in Edit mode, how to get the associated changetype and sym of change category?

    I learnt that have to make the webeinge search operation, can I get help on constructing the url, web engine operation call and processing a return value with an example.

     

    Thank you,

    Venkat



  • 8.  Re: how to get the read only field value to the java script function

    Posted Oct 25, 2017 11:07 AM

    Hi Venkat.

     

    I'm not quite sure, what exactly you want to achieve.

    If the change order is displayed in edit mode
    the initial (stored in the DB) values are displayed in the correponding input fields.

     

    If you are intersted in those values the same approach as before can be used.
    var changetype_sym= "$args.chgtype.sym";
    var category_sym="$args.category.sym";

     

    But of course this approach doesn't work if you are intersted in the values, when the user has changed (edited) the category or changetype.

     

    The most easy way would be to ask the DOM, because the data you are looking for is already available, instead of doing an additional webengine call.

     

    While the category is a normal text input field which should be accessible by

     

    var category_sym=document.getElementsByName("KEY.category")[0].value;

     

    the change type field is a dropdown, which is a bit more complicate

     

    var changetype_el=document.getElementsByName("SET.chgtype")[0]
    var changetype_idx=changetype_el.selectedIndex;
    var changetype_sym=changetype_el.options[changetype_idx].value;

     

    * not tested *

     

    Hope this helps.
    Regards
    .............Michael



  • 9.  Re: how to get the read only field value to the java script function

    Posted Oct 25, 2017 11:47 AM

    I am trying to figure it out the user changed (edited ) category name and category associated changetype (not the change order change type).

     

     

    var chgcat_element = document.main_form.elements["SET.category"];
    console.log(chgcat_element.value);
    if (typeof chgcat_element != "undefined"){
    var url=cfgCgi+"?SID="+cfgSID+"+FID="+fid_generator()+ 
        "+OP=SEARCH+FACTORY=chgcat" + 
        "+QBE.EQ.delete_flag=0" + 
        "+QBE.EQ.code="+escape(chgcat_element.value)
         "+HTMPL=list_chgcat_json.htmpl";
    var result = SyncAjaxCall(url,"GET");
    console.log(result);
    result = result.substring(result.indexOf("{")); 
    if( result.charCodeAt(result.length-1) == 0 ) { 
        result = result.substr(0, result.length-1); 
    } 
    var data = eval('(' + result + ')');
    console.log(data);
    }

     

    The content of list_chgcat_json.htmpl is 

     

    {
    "records" : [
    <PDM_LIST SOURCE=list SORT=$sort START=$start ESC_STYLE=C>
    <PDM_IF $list.ROW \> 0>,</PDM_IF>
    {
    "changetype" : '<PDM_FMT ESC_STYLE=JS2>$list.chgtype.sym</PDM_FMT>',
    "tenantname" : '<PDM_FMT ESC_STYLE=JS2>$list.tenant.name</PDM_FMT>'
    }
    </PDM_LIST>
    ]
    }

     

    but the operation is not returning desired results and I could see the entire list_chgcat.htmpl page in console of browser.

     

    Thank you.

    Venkat



  • 10.  Re: how to get the read only field value to the java script function
    Best Answer

    Posted Oct 25, 2017 12:08 PM

    Now I understand:)

    I'm not able to test this currently....

    What about the idea using

    "OP=DISPLAY_FORM+HTMPL=list_chgcat_json.htmpl+KEEP.chgcat_code="+chgcat_element.value

     

    and in your json Generator use a

    <pdm_list FACTORY=chgcat PREFIX=mylist WHERE="code=$args.KEEP.chcat_code">

    ...

     

    Will take a look into it again tomorrow.

    Regards

    .........Michael



  • 11.  Re: how to get the read only field value to the java script function

    Posted Oct 27, 2017 06:03 AM

    Thank you Michael Mueller.



  • 12.  Re: how to get the read only field value to the java script function

    Posted Oct 27, 2017 06:12 AM

    You're welcome ,Venkat. I assume, the different approach is working for you now?



  • 13.  Re: how to get the read only field value to the java script function

    Posted Oct 27, 2017 06:44 AM

    Yes, Correct, the server call returning the pdm_list response and I'm parsing the JSON data for desired values as follows.

    content of list_chgcat_json.htmpl

     

    {
    "records" : [
    <pdm_list FACTORY=chgcat PREFIX=mylist WHERE="code='$args.KEEP.chgcat_code'">
    {
    "changetype" :<PDM_FMT ESC_STYLE=JS2>"$mylist.chgtype.sym"</PDM_FMT>, "catname" : <PDM_FMT ESC_STYLE=JS2>"$mylist.sym"</PDM_FMT>
    }
    </PDM_LIST>
    ]
    }

     

    JavaScript content

     

    var url = cfgCgi + "?SID=" + cfgSID + "+FID=" + fid_generator() +
                   "OP=DISPLAY_FORM+HTMPL=list_chgcat_json.htmpl+KEEP.chgcat_code=" + chgcat_element.value
                   var result = SyncAjaxCall(url, "GET");
              if (typeof result != "undefined") {
                   result = result.substring(result.indexOf("{"));
                   var obj = JSON.parse(result);
              }
              if (typeof obj != "undefined") {
                   if (obj.records != "undefined")
                        if (obj.records.length > 0) {
                             cat_sym = obj.records[0].catname; // Category name
                             cat_chgtype = obj.records[0].changetype; // Category Change type sym
                             }
                        }
              }

     

     

    I would like to try and work on SDM Server calls then playing response  in java script to present the required data on SDM edit forms (Ex. Dependency dropdowns ect.)   Very interesting area.

     

    Regards,

    Venkat



  • 14.  Re: how to get the read only field value to the java script function

    Posted Nov 08, 2017 01:44 PM

    Hi,

    using same code Im trying to list attributes of a custom srel attribute in cnt (srel to grp).

    When I try to list it's self (zdefault_group) it works fine, but when I try lets say       zdefault_group.last_name it's not working and there are lot of errors of kind below

     

    SQL Execute  failed: [Microsoft SQL Server Native Client 11.0] [ SQL Code=156 SQL State=42000]       Incorrect syntax near the keyword 'LEFT'.


  • 15.  Re: how to get the read only field value to the java script function

    Posted Nov 09, 2017 02:23 AM

    Hi Horuc,

     

    Can you update the your code and what you are trying to achieve.

     

    Regards,

    Venkat