How can we submit Record Producer on a Target table along with the mapping of variables?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 08:06 AM
Hi @Mark Roethof , @Ankur Bawiskar
"I need to submit a Record Producer via script to a target table, 'Workplace Service', including mapping the variables. The form includes a section displaying all the Record Producer's variables, and I want to ensure that when a user submits the Record Producer, their variable inputs are correctly mapped to the form."

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 08:09 AM
Hi there,
Please share what you've tried so far, what is not working, where you are stuck.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 10:09 AM - edited 07-31-2024 10:11 AM
Hi @Mark Roethof
Thanks for your response
"I am attempting to submit a Record Producer through the Virtual Agent 'Script Action' utility using a REST API call with the following script:
(function execute() {
// Define the Record Producer's sys_id and the target table name
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('URL');
request.setHttpMethod('POST');
// Example credentials: UserName="admin", Password="admin"
var prop = gs.getProperty('internal.rest.api_authentication');
var parsed = JSON.parse(prop);
var user = parsed.username;
var password = parsed.password;
var obj = {};
obj.requested_for = vaInputs.requested_for.getDisplayValue().toString();
request.setBasicAuth(user, password);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader('Content-Type', 'application/json');
// Setting up the request body with dynamic variables
request.setRequestBody(JSON.stringify({
'variables': obj,
'short_description': 'test',
'workplace_service': '603a717387073d10627cc8470cbb3544',
'workplace_service_item': '35b9d6291b754a90217c9686b04bcb7a',
'u_category': 'Request Catering Assistance'
}));
var response = request.execute();
gs.log(response.getBody());
})();
Currently, I have hardcoded the variable inputs, but they should be dynamic. The variables are not mapping correctly on the form as expected." Also Is there any other way we can submit the Record Producer and map the variable of Record Producer on Target Table through Virtual Agent?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 10:14 AM
You could ofcourse create a Subflow or Flow Action for this and trigger that from Virtual Agent. This is also possible ofcourse, though more difficult for future colleagues.
Whats the issues you are having in making the inputs dynamic? Or is that you don't have Virtual Agent knowledge for this and need help this?
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 11:46 AM
Hi @Mark Roethof ,
I do have worked on VA before and was trying the below approach to pass in what user has filled out:
Code which I tried by passing VA Inputs here:
(function execute() {
// Define the Record Producer's sys_id and the target table name
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('URL');
request.setHttpMethod('POST');
// Example credentials: UserName="admin", Password="admin"
var prop = gs.getProperty('internal.rest.api_authentication');
var parsed = JSON.parse(prop);
var user = parsed.username;
var password = parsed.password;
//var obj = {};
//obj.requested_for = vaInputs.requested_for.getDisplayValue().toString();
request.setBasicAuth(user, password);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader('Content-Type', 'application/json');
// Setting up the request body with dynamic variables
request.setRequestBody("{'variables':{'requested_for':" + vaInputs.requested_for + ",'priority':"+vaInputs.priority}, 'short_description':'test','workplace_service':'603a717387073d10627cc8470cbb3544','workplace_service_item':'35b9d6291b754a90217c9686b04bcb7a'}");
var response = request.execute();
gs.log(response.getBody());
})();
In my code above , I have tried passing VaInputs for two variables i.e. Requested for and Priority but that does not seems to work.
Can you help where am I missing a gap here?