Help with a catalog item form

cicgordy
Tera Guru

The main form includes a reference type variable "user_submitted_software" that references to the software table "u_software".

If a user selects any software from the "user_submitted_software" variable list, it should then verify whether, on that particular software record in the "u_software" table, another checkbox field named "u_additional_justification" is set to true. If it is set to true, then another variable I created should be displayed on the form, named "additional_justification_requirements". If false, the form remains unchanged.

Please note that the "user_submitted_software" variable is empty by default on the form, and the "additional_justification_requirements" variable should be hidden by default(at moment is not). It should only become visible if the software selected in the "user_submitted_software" variable has the "u_additional_justification" checkbox set to true in the backend on the "u_software" table.

 

 

Thanks

1 ACCEPTED SOLUTION

@Anirudh Pathak Hi, I got it working by only using a catalog client script, thanks for your help anyway, here is what I did: 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        g_form.setDisplay('additional_justification_requirements', false); 
        return;
    }
    g_form.getReference('user_submitted_software', callback);

    function callback(obj) {
        // Check if u_access_request is true on the referenced record
        if (obj.u_additional_justification == 'true') {
            // Show the access_request_info variable
            g_form.setDisplay('additional_justification_requirements', true);
        } else {
            // Hide the access_request_info variable
            g_form.setDisplay('additional_justification_requirements', false);
        }
    }
}

View solution in original post

15 REPLIES 15

Hi @cicgordy ,

can you share the exact script you wrote?

 

There you go:

 

 

- Script include

cicgordy_0-1708613278110.png

 

 

 

 

 

- Catalog client script: 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   var software = g_form.getValue('user_submitted_software');
   var submittedSoftware= new GlideAjax('software_aditional_requirements');
   submittedSoftware.addParam('sysparm_name','getData');
   submittedSoftware.addParam('sysparm_software',software);
   submittedSoftware.getXMLAnswer(getSoftware);
   
   function getSoftware(response){
    if(response == 'yes') {
        g_form.setDisplay('additional_justification_requirements',true);
    }
    else {
            g_form.setDisplay('additional_justification_requirements',false);
    }
   }
   
}

Hi @cicgordy ,

Seems like there is an error in your script include. Why you have removed the auto generated code from your script include?

@Anirudh Pathak , What do you mean by auto generated code? I haven't removed anything just copied your script

Hi @cicgordy ,

when you create a new script include and check client callable it generates this code -

var script_include_name= Class.create();
script_include_name.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type: 'script_include_name',