Scripted REST API for catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 01:29 AM
Hello Community,
I have a catalog item in which i have fields customer, assignment group, Description which all are type of string or single line text, now i have created flow in flow in flow i have done mapping in update record action for ritm form customer field of type reference should be mapped with value filled in customer variable, same with assignment group but this will not happen since both type are not same .same mapping for sc task also.
Now i need to create a scripted rest api for this catalog item to create a request such that if user fills customer as XYZ and assignment group as abc, then those values should be filled in company, assignment group fields in ritm and sc task forms if those values are present in customer table and assignment group tables..
please guide with logic
Thanks & regards,
Santh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 05:34 AM - edited 10-25-2024 05:35 AM
Hello @sanathk
For this you need to use the cart api to create the request and their RITM and also you need to apply some validation like you get the assignment group and company as string field so you need to create two method to validate the company and assignment group in respective tables of company (core_company and sys_user_group).If the record will be validate or the string that you put in variable then you should return the name the company and group
function getCustomerVar(customerVar){
var grCustomer = new GlideRecord("customerTable");// put your backend name of the customer table
grCustomer.addQuery('name',customerVar);
grCustomer.query();
if(grCustomer.next()){
return grCustomer.getValue('name') // if validate it return the name
}
else{
return ; // return nothing if not present
}
function getGroupValidate(groupVar){
var getGroup = new GlideRecord("sys_user_group");
getGroup.addQuery('name',groupVar);
getGroup.query();
if(getGroup.next()){
return getGroup.getValue('name') // if validate it return the name
}
else{
return ; // return nothing if not present
}
}
Also check below thread , how we can create the Request by cart API
https://www.servicenow.com/community/developer-forum/create-ritm-vai-cart-api/m-p/2552265
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 05:36 AM
And pass the catalog variable value in those method that i define above
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 07:28 AM
Hi @Sanjay191 ,
Thanks for your response , yes we can do as you said.
I tried this way getting the string value like customer XYZ then i did mapping to customer field in update record action in flow with customer variable and then in the script i am taking the input and then querying in customer table and then checking if available then getting sys_id and then passing to customer field it worked.
Thank you.
Santh K