How can you access a field on a record producer from a client script within a multirow variable set?

Peter Namkoong
Tera Contributor

I am trying to figure out if it is possible to access or pass the value of a field on a Record Producer (RP) on the Service Portal to a MultiRow Variable Set (MRVS). I currently have a field on the RP that lets you specify a certain week and the MRVS lets you specify a record for a day of that chosen week. please see the images below:

Record Producer field for selecting a week

find_real_file.png

MRVS field for selecting a date from that week

find_real_file.png

currently, I am able to access the RP field by getting the HTML DOM element ID, but I am noticing some inconsistent behaviors when doing so. Is there any way I can access the field directly through some sort of dot-walking? I have tried using "producer.variables.week_ending" to access the field but that doesn't work within the MRVS client script.

 

I would appreciate your support!

1 ACCEPTED SOLUTION

Zach Biewend1
Giga Expert

I haven't found an elegant solution to this, but I did come up with a workaround. It takes a few steps but it worked very well for me in the past. 

Create a GlideAjax script include and client script on the RP. onChange of week_ending, write that value to a user preference (sys_user_preference) for the current user. Name it something unique... (<RP name>.week_ending).

In your MRVS, call a GlideAjax to fetch the value that's been written to that user preference. 

Then for good house keeping, onSubmit of the RP, clear that value from the user preference. 

 

Let me know if this works for you! 

View solution in original post

9 REPLIES 9

Thanks for the links! I tried them out but, it seems to be more focused on the Now Platform view and doesn't work for the SP view. 

I appreciate your help!

Zach Biewend1
Giga Expert

I haven't found an elegant solution to this, but I did come up with a workaround. It takes a few steps but it worked very well for me in the past. 

Create a GlideAjax script include and client script on the RP. onChange of week_ending, write that value to a user preference (sys_user_preference) for the current user. Name it something unique... (<RP name>.week_ending).

In your MRVS, call a GlideAjax to fetch the value that's been written to that user preference. 

Then for good house keeping, onSubmit of the RP, clear that value from the user preference. 

 

Let me know if this works for you! 

At least until there is more of a direct way of accessing the variable, I think this could be the best solution to the problem I was having. I never thought about using the user preference table to temporarily store the value, but it seems to be a good enough solution!

Thank you for your help! 

Yamilla Manjko
Tera Guru

You can use the g_service_catalog API:

 

g_service_catalog.parent.getValue("variable_name")

 

https://developer.servicenow.com/dev.do#!/reference/api/rome/client/g_service_catalogClientAPI

Using g_service_catalog API worked! thanks!