Help with a Catalog Client script

jonathangilbert
Kilo Sage

Hi All

 

I seem to have an issue with this client script not executing correctly on a Catalog Item. The script is looking up a user on the sys_user table using a callback function. Then depending on if the field on the looked up user record has a value in it, will then make a variable on the catalog item hidden or visible. As it currently stands the form is hidding variables even when there is no entry on the looked up field, whereas it shoudl be displaying the variabIe.

Ithink i am missing something between each of the "if" statements. Can anyone assist?

 

 

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {
      return;
   }
   
    var usr = g_form.getReference('name_of_existing_colleague',callBack);
   
}
function callBack(usr){
   

     if (usr.u_dunsaperpprodusername != "") {
     g_form.setDisplay('sap_ecc_production',false);
    } else
    g_form.setDisplay('sap_ecc_production',true);
 

//AM I MISSING SOMETHING TO SEPERATE THE ABOVE FROM THE BELOW  "IF" STATEMENT 
 

    if (usr.u_dunsaperppreprodusername != "") {
   g_form.setDisplay('sap_ecc_pre_production',false);
    } else
    g_form.setDisplay('sap_ecc_pre_production',true);


    if (usr.u_dunsaperpdev100username != "") {
     g_form.setDisplay('sap_ecc_development_100',false);
    } else
    g_form.setDisplay('sap_ecc_development_100',true);


    if (usr.u_dunsaperpdev102username != "") {
   g_form.setDisplay('sap_ecc_development_102',false);
    } else
    g_form.setDisplay('sap_ecc_development_102',true);


    if (usr.u_dunsaperpqausername != "") {
     g_form.setDisplay('sap_ecc_qa',false);
    } else
    g_form.setDisplay('sap_ecc_qa',true);


    if (usr.u_dunsaperpsandboxusername != "") {
   g_form.setDisplay('sap_ecc_sandbox',false);
    } else
    g_form.setDisplay('sap_ecc_sandbox',true);


    if (usr.u_dunsapewmprodusername != "") {
     g_form.setDisplay('sap_ewm_production',false);
    } else
    g_form.setDisplay('sap_ewm_production',true);


    if (usr.u_dunsapewmpreprodusername != "") {
   g_form.setDisplay('sap_ewm_pre_production',false);
    } else
    g_form.setDisplay('sap_ewm_pre_production',true);


    if (usr.u_dunsapewmdevusername != "") {
     g_form.setDisplay('sap_ewm_development',false);
    } else
    g_form.setDisplay('sap_ewm_development',true);


    if (usr.u_dunsapewmqausername != "") {
   g_form.setDisplay('sap_ewm_qa',false);
    } else
    g_form.setDisplay('sap_ewm_qa',true);


    if (usr.u_dunsapewmsandboxusername != "") {
     g_form.setDisplay('sap_ewm_sandbox',false);
    } else
    g_form.setDisplay('sap_ewm_sandbox',true);


    if (usr.u_dunsappoprodusername != "") {
   g_form.setDisplay('sap_po_production',false);
    } else
    g_form.setDisplay('sap_po_production',true);


    if (usr.u_dunsappopreprodusername != "") {
     g_form.setDisplay('sap_po_pre_production',false);
    } else
    g_form.setDisplay('sap_po_pre_production',true);


    if (usr.u_dunsappodevusername != "") {
   g_form.setDisplay('sap_po_development',false);
    } else
    g_form.setDisplay('sap_po_development',true);


    if (usr.u_dunsappoqausername != "") {
     g_form.setDisplay('sap_po_qa',false);
    } else
    g_form.setDisplay('sap_po_qa',true);


    if (usr.u_dunsapposandboxusername != "") {
   g_form.setDisplay('sap_po_sandbox',false);
    } else
    g_form.setDisplay('sap_po_sandbox',true);


    if (usr.u_dunsaphrprodusername != "") {
     g_form.setDisplay('sap_hr_production',false);
    } else
    g_form.setDisplay('sap_hr_production',true);


    if (usr.u_dunsaphrdevusername != "") {
   g_form.setDisplay('sap_hr_development',false);
    } else
    g_form.setDisplay('sap_hr_development',true);


    if (usr.u_dunsaphrqausername != "") {
     g_form.setDisplay('sap_hr_qa',false);
    } else
    g_form.setDisplay('sap_hr_qa',true);


    if (usr.u_dunsaphrsandboxusername != "") {
   g_form.setDisplay('sap_hr_sandbox',false);
    } else
    g_form.setDisplay('sap_hr_sandbox',true);


    if (usr.u_dunsapbwprodusername != "") {
     g_form.setDisplay('sap_bw_production',false);
    } else
    g_form.setDisplay('sap_bw_production',true);


    if (usr.u_dunsapbwpreprodusername != "") {
   g_form.setDisplay('sap_bw_pre_production',false);
    } else
    g_form.setDisplay('sap_bw_pre_production',true);


    if (usr.u_dunsapbwdevusername != "") {
     g_form.setDisplay('sap_bw_development',false);
    } else
    g_form.setDisplay('sap_bw_development',true);


    if (usr.u_dunsapbwqausername != "") {
   g_form.setDisplay('sap_bw_qa',false);
    } else
    g_form.setDisplay('sap_bw_qa',true);


    if (usr.u_dunsapbwsandboxusername != "") {
     g_form.setDisplay('sap_bw_sandbox',false);
    } else
    g_form.setDisplay('sap_bw_sandbox',true);


    if (usr.u_dunsapbatchmanprodusername != "") {
   g_form.setDisplay('sap_batchman_prod',false);
    } else
    g_form.setDisplay('sap_batchman_prod',true);


    if (usr.u_dunsapbatchmanpreprodusername != "") {
     g_form.setDisplay('sap_batchman_pre_production',false);
    } else
    g_form.setDisplay('sap_batchman_pre_production',true);


    if (usr.u_dunsapbatchmandevusername != "") {
   g_form.setDisplay('sap_batchman_dev',false);
    } else
    g_form.setDisplay('sap_batchman_dev',true);


    if (usr.u_dunsapbatchmanqausername != "") {
     g_form.setDisplay('sap_batchman_qa',false);
    } else
    g_form.setDisplay('sap_batchman_qa',true);


    if (usr.u_dunsapsolmanprodusername != "") {
    g_form.setDisplay('sap_solman_production',false);
     g_form.setDisplay('active_control',false);
    } else
    g_form.setDisplay('sap_solman_production',false);
    g_form.setDisplay('active_control',true);

    if (usr.u_dunsapsolmandevusername != "") {
     g_form.setDisplay('sap_solman_development',false);
    } else
    g_form.setDisplay('sap_solman_development',true);



}
1 ACCEPTED SOLUTION

Hi, I have found the issue. It was due to an ACL on the sys_user table, which prevented the results of the client script from being displayed. Thankyou for you assistance anyway, it was very kind of you 

 

View solution in original post

14 REPLIES 14

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Can you simplify the scenario?
shorted the script and explain what you expect if variable u_dunsaperppreprodusername  has value ?

 

In your example you have the below piece of code repeated, why?

     if (usr.u_dunsaperpprodusername != "") {
     g_form.setDisplay('sap_ecc_production',false);
    } else
    g_form.setDisplay('sap_ecc_production',true);
-Anurag

Hi Anurag

So on my scrip on line 7, I have the callback which is looking up the user record on the sys_user table.

 

If the field "u_dunsaperpprodusername" on the that users record has a value in it then the variable "sap_ecc_production"  on the form should be hidden.

If the field "u_dunsaperpprodusername" on the that users record doesnt have a value in it then the variable "sap_ecc_production"  on the form should be visable.

So that becomes this

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {
      return;
   }
   
    var usr = g_form.getReference('name_of_existing_colleague',callBack);
   
}
function callBack(usr){
   

     if (usr.u_dunsaperpprodusername != "") {
     g_form.setDisplay('sap_ecc_production',false);
    } else
{
    g_form.setDisplay('sap_ecc_production',true);
 }
}

 

Test this and reply if this works. Just for this field. 

then we will take the other fields on.

-Anurag

Hi Anurag, 

Your script doesnt work, I can get it to work when it is only doing one field usign this script:-

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {
      return;
   }
   
    var usr = g_form.getReference('name_of_existing_colleague',callBack);
   
}
function callBack(usr){
   

     if (usr.u_dunsaperpprodusername != "") {
     g_form.setDisplay('sap_ecc_production',false);
    } else
    g_form.setDisplay('sap_ecc_production',true);
}