How to pass variable name while creating Catalog Client Script using Table API?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I am trying to create Catalog Client Scripts using ServiceNow Table API like given below. The Variable Name property is not getting updated even though I am passing the sys_id of the variable in "cat_variable". How can we add the Variable Name as well during the creation of Catalog Client Script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @iwsservicen,
Passing sys_id of catalog variable is not enough, you must pass catalog variable name as well so that your catalog client script would recognize.
Here's the solution with shots I implemented on my PDI:
First I created example catalog item and created two single line text variables:
Then created POST method Table API all through System Web Services > REST > REST API Explorer
Configure the options as mentioned in shot below:
Put the following JSON in Request Body's Raw section:
{
"name":"Update Email Address",
"type":"onChange",
"cat_item":"d17a9710933076109d0a7c5efaba10b8", // sys_id of Cat item
"cat_variable":"03ba9f90933076109d0a7c5efaba108f", // sys_id of Cat variable
"variable_name":"mailbox_display_name", // name of Cat variable
"script":"function onChange(control, oldValue, newValue, isLoading) {\n if (isLoading || newValue == '') {\n return;\n }\n // First Field Value\n var FirstFieldValue = g_form.getValue('mailbox_display_name');\n\n // Second Field\n g_form.setValue('mailbox_email_address', FirstFieldValue + '@tenantname.onmicrosoft.com');\n}"
}Replace sys_ids and catalog variable name with your actual one. You can find the variable name here:
Now click on the Send button in REST API Explorer.
Now you should be able to see a success message and Client script created for your catalog item:
when you open this client script record, don't forget to set Variable name to mailbox_display_name:
Now test this by clicking on Try it button on your catalog item form:
you can see in above shot when I wrote my name in Mailbox Display Name field, Mailbox Email Adress field automatically got updated.
Hope this helps!
If my response helped, please mark it as the accepted solution and helpful so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited a week ago
Hi @Community Alums , Attaching my input JSON and screenshots here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited a week ago
Hi @Community Alums , Thank you for your reply, I tried calling the Table API again with the same JSON input body as you tried , but still I am facing the same issue as before - Variable name is not getting updated. Also wanted to add one thing, I am having this variable inside a variable set.
This is my input body and the output screenshot.
{
"name": "Update Email Address",
"type": "onChange",
"cat_item": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", //sys Id of catalog item
"cat_variable": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", //sys Id of variable
"variable_name": "mailbox_display_name",
"script": "function onChange(control, oldValue, newValue, isLoading) {\n if (isLoading || newValue == '') {\n return;\n }\n // First Field Value\n var FirstFieldValue = g_form.getValue('mailbox_display_name');\n\n // Second Field\n g_form.setValue('mailbox_email_address', FirstFieldValue + '@tenantname.onmicrosoft.com');\n}"
}
