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

Pretty much same maybe some indentation and {} in the else block

 

Now similarly add one more if at a time and see if that works. If i understand correctly, you are checking to see f these fields on the user table are populated or not, if not then you want to show the corresponding variable.

-Anurag

Hi, you understand correctly, when I add another field in, it stops working again. To me it needs something to seperate the fields into blocks of "If and else"

 

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);

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

Try this

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

    if (isLoading || newValue == '') {
        return;
    }

    var usr = g_form.getReference('name_of_existing_colleague', callBack);

}

function callBack(usr) {
//Field 1
    if (usr.u_dunsaperpprodusername != "") {
        g_form.setDisplay('sap_ecc_production', false);
    } else {
        g_form.setDisplay('sap_ecc_production', true);
    }
//Field 2
    if (usr.u_dunsaperppreprodusername != "") {
        g_form.setDisplay('sap_ecc_pre_production', false);
    } else {
        g_form.setDisplay('sap_ecc_pre_production', true);
    }

}
-Anurag

Hi,

No that does not work, if i put a value in the u_dunsaperppreprodusername  on the users record, and leave u_dunsaperpprodusername blank, the script is hiding both the variables on the form, where it should only be hiding 1

 

Can you add some alerts inside the ifs on callback function. 

Feels like there is some other scripts that might be impacting this

 

function callBack(usr) {
//Field 1
    if (usr.u_dunsaperpprodusername != "") {
alert('1');
alert('value = '+ usr.u_dunsaperpprodusername );
        g_form.setDisplay('sap_ecc_production', false);
    } else {
alert('2');
        g_form.setDisplay('sap_ecc_production', true);
    }
//Field 2
    if (usr.u_dunsaperppreprodusername != "") {
alert('3');
alert('value = '+ usr.u_dunsaperppreprodusername);
        g_form.setDisplay('sap_ecc_pre_production', false);
    } else {
alert('4');
        g_form.setDisplay('sap_ecc_pre_production', true);
    }

}
-Anurag