Automatically populate one variable on a Catalog item based on the value of another variable

jfinn
Kilo Expert

Hi,

I am currently working on a new catalog item to allow for users to submit requests for access to shared drives.   We have the drive information stored in a table called Storage File Shares (cmdb_ci_storagefileshares).   This includes the following information:

  • Path
  • Approver
  • Read Access Group
  • Write Access Group

On my catalog item, I have created two variables, one call 'Path' and the other called 'Approver'.   What I am looking to do is have the Approver value automatically update when I select a value in the 'Path' variable.

A basic view of what I am trying to do is below.   The table represents my storage file shares table which is extended off the cmdb_ci table.

PathApprover
\\fileshare01\testTom Jones
\\fileshare01\HRMary Jones
\\fireshare02\newfolderJohn Jones

If I select \\fileshare01\test in the 'Path' variable (reference field to the table above) on my catalog item when logging a new request, can the second variable then update with the approvers name, ie. Tom Jones?

I am pretty new to all of this and am looking to see if this can be easily done or if this will require more advanced scripting.   I have done some basic scripting recently within the application but am a newbie so to speak.

Any assistance or thoughts on this would be appreciated.

Cheers.

1 ACCEPTED SOLUTION

Sorry, try this:



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


    if (isLoading || newValue == '') {


          return;


    }




var path = g_form.getReference('Path');


          g_form.setValue('Approver', path.u_approver1);


               


}


View solution in original post

7 REPLIES 7

BryanS413339635
Tera Guru

Just add an approver column to your table and map the approvers to the paths. Then you can do an onChange client script to populate the approver field when the path fields value changes.


Hi Brian,



Yes, that was what I was thinking would be needed.   However, I have tried a couple of different scripts already but have been unable to pull through the information from the table.



Currently the table fields on my table are called:



ValueField Name
Pathu_path
Approveru_approver1


My variables on the catalog item are called:



Variable ValueVariable Name
PathPath
ApproverApprover


Any ideas?


In the catalog client script, you would just set the Type to onChange, for variable name pick the variable for your path field. I think the script would look something like this:



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


    function populateApprover(path) {


          g_form.setValue('Path', path.u_approver1);


    }


    if (newValue == '') {


          return;


    }


    var path = g_form.getReference('Path', populateApprover);


}


Hi Bryan,



Sorry for misspelling your name in my previous post and many thanks for your help on this.   I have tried the code that you have suggested but it is still not working.



My variables are both set up as reference variables as I was manually entering the details initially but am looking to now auto-populate the data so wondering if this would have anything to do with why this is not working. I have tried changing this to a Single Line Text variable type but not working still.



The current variables are set up as follows:



Variable Value                                                   Variable Name                                                         Type                                                                 References table:                     Display field on Reference Table            
PathPathReferencecmdb_ci_storage_fileshare u_path
ApproverApproverSingle Line Text