Scripted creation of request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 08:39 AM
Hello All,
I have a requirement to create a script that will automate the creation of a catalog request.
- When a new user is created on the sys_user table with the following conditions:
- company = ACME
- source = new_hire_table
- new_hire_active = Y
- Kick-off the creation of a catalog item request.
I created a business rule to run after and insert
with the following advanced script
Just for clarity in the event that you cant read the PIC
condition:
current.u_new_hire_active == 'Y' && current.source == 'new_hire_table' && current.company == 'ACME'
Script:
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 08:48 AM - edited 09-20-2023 08:53 AM
Hello @Marcelo Pedrey1
You can use Cart API
Below link might help you....!!
YouTube link - https://youtu.be/EciIRYzSKBs?feature=shared
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 10:09 AM
Hello Vishal,
This did not seem to work, I failed to mention that it is an actual order guide that it is supposed to kick off
Thank you,
Best
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 10:22 AM
Hello Marcelo,
You want to raise catalog Item request (Order Guide) from business rule? Right..??
The link provided above should work.
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 08:26 AM
Hello Vishal,
Yes, i would like to open an Order Guide from the business rule. I have tried that and it opens the order guide as a RITM not as a request and does not trigger any of the other catalog items within the order guide. I have updated the code and still am getting nowhere. I must be doing something wrong, hopefully a fresh set of eyes can let me know.
(function runBusinessRule(current) {
// Check if the conditions for executing the script are met
if (
current.company == "ACME" &&
current.source == "new_hire_table" &&
current.u_new_hire_active == "Y"
) {
// Create an object with JSON data
var json = {
"requested_by": "a982fa3047e53d50ec63fc29736d43bc"
};
// Continue with your existing script logic
// ...
// Now, open the "New Hire Onboarding" order guide
var orderGuideName = "New Hire Onboarding";
var nowGR = new GlideRecord("sc_cat_item_guide");
// Find the order guide by name
if (nowGR.get("name", orderGuideName)) {
// Initialize a ScriptableOrderGuide object
var sog = new SNC.ScriptableOrderGuide(nowGR.getValue("sys_id"));
// Set the variables in the order guide
sog.variables.orderGuide_requested_by = "a982fa3047e53d50ec63fc29736d43bc";
sog.variables.orderGuide_employment_type = "employee";
sog.variables.orderGuide_employment_subtype = "associate";
sog.variables.orderGuide_start_date = current.u_glide_date_1;
sog.variables.orderGuide_new_employee_name = current.name;
sog.variables.orderGuide_company = "1fae00ed8790a11004380e15dabb3582";
sog.variables.orderGuide_department_name = current.department;
sog.variables.orderGuide_manager = current.manager;
sog.variables.orderGuide_manager_email = current.manager.email;
sog.variables.orderGuide_is_new_hire_manager = current.u_managerstatus;
sog.variables.orderGuide_job_title = current.title;
sog.variables.orderGuide_add_user_to_okta_ad_group = "true";
// Process the order guide
var result = sog.process(new JSON().encode(json));
if (!result) {
gs.log("Processing the scriptable order guide failed with message: " + sog.getMessage());
} else {
// Get the request created by the order guide
var request = sog.getRequest();
gs.log("Request created - " + request.sys_id);
}
} else {
gs.error("Order guide 'New Hire Onboarding' not found.");
}
} else {
gs.log("Script conditions not met. Skipping execution.");
}
})(current);