How to autopopulate field in request table based on input given before submitting the request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 11:33 AM
Hi,
I need to autopopulate custom field in request table based on input given in variable before submitting the request through catalog item. I have created as a variable set because i will be using that variable in multiple catalog items and created that custom field in request table as well.
Can someone please suggest me on this.
Thanks in advance!
Priyanka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 12:26 PM - edited 08-28-2023 12:34 PM
Hello @Priyanka77 ,
For this, you can write a function like this:
function calculateScript() {
var variablesResponses = [];
var val = current.variables.getElements();
for (var i = 0; i < val.length; i++) {
var j = {};
var variableObject = val[i].getQuestion();
j.question = variableObject.getLabel();
j.response = variableObject.getDisplayValue();
variablesResponses.push(j);
}
return variablesResponses;
}
"variablesResponses" will return a JSON array of catalog variables; you can call this function for your custom field as per your requirement.
@Priyanka77 , Please mark my answer as "Accept as Solution" and "Helpfuls." If it works for you.
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 01:15 AM
Thanks for your response @Community Alums
But where I need to write this function and if its business rule then table will be sc_request?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 02:29 AM
how would you know which REQ is there even before submitting the request?
are you using flow designer or workflow for your catalog item?
it would be nice if you share screenshots of the custom field and other things.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 01:35 AM
Thanks for your response @Ankur Bawiskar
I am using that variable in request table as well and I am mapping that after submission of request. I have achieved the functionality via business rule. Thank you