Populate New RITM with variables from another RITM

Bruler1230
Tera Expert

Hello,

I have a requirement to allow a user to select one of their previous RITMs from a reference field, and when selected, it will automatically populate the variables on the new RITM service portal form.

Example..a user had submitted a ticket for access to a shared drive, which was completed and closed. The access is only temporary and must be revalidated every so often. So when a user comes to the shared drive access form, if it is a request for revalidation, they can choose the previous RITM they submitted, and that would auto populate the variables on the form with the variables from the previous RITM.

I have a reference qualifier on the reference field to only show RITMs for the logged in user and for that particular cat item. 

None of these variables are mapped to a field on a table. Just displayed in the variable editor

I have tried an onChange client script, but havent had any luck. Would a script include be required to achieve this? or can it be achieved with a glide query in an onchange client script?

var ritm = g_form.getValue('test');  //this is getting the value of what is selected in the reference field

var gr = new GlideRecord(sc_req_item);

gr.addQuery('sys_id', ritm);

gr.query();

while(gr.next() {

//how do i populate the variables on the current form with the variables from the selected RITM?

}

 

Please let me know if any other info is needed.

Thanks!

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

You'd create an onChange client script that utilizes GlideAjax (script include) to communicate with the server and pass your reference field sys_id and query the table to get the record and then build an object of the variables you need to bring back to the client, then in the client, set the value for those fields with the same values you just retrieved.

GlideAjax cheat sheet (use an example to get you started): https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

Allen Andreas
Administrator
Administrator

Hi,

You'd create an onChange client script that utilizes GlideAjax (script include) to communicate with the server and pass your reference field sys_id and query the table to get the record and then build an object of the variables you need to bring back to the client, then in the client, set the value for those fields with the same values you just retrieved.

GlideAjax cheat sheet (use an example to get you started): https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thanks for the response. None of the variables are saved to a field on the sc_req_item table...how do i set the variables from the script include?

Hi,

By design, variables are available on the RITM record using:

gr.variables.variable_name

For example. So if the user is selecting their past RITM...it has the variables associated to it, which you'd then extract and pass back to the new catalog item for the new form to be filled in with the same values.

https://developer.servicenow.com/dev.do#!/reference/api/paris/server/no-namespace/c_GlideRecordScope...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank you. i created a script include and catalog client script and it seems to be working. Thanks for the help.