Populate the parent field with the sys_id of the record it was openned from
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 04:13 AM
Hi everyone, Im trying to create a UI Action that will redirect the user from the "Problem" to the Catalog, and when the user opens a "Incident" or a "Ritm" the "Parent" field should be the number of the problem is was created from, but Im not being abble to make this work ...
Does anyone know how to do this?
Code that I have right now:
//Update saves incidents before going to the catalog homepage
current.update();
var url;
var activeCatalogsCount = sn_sc.Catalog.getCatalogCount();
if (activeCatalogsCount === 1) {
url = "catalog_home.do?sysparm_view=catalog_default&sysparm_parent_table=" + current.sys_class_name + "&sysparm_parent_sys_id=" + current.sys_id;
}
else {
url = "catalogs_home.do?sysparm_view=catalog_default&sysparm_parent_table=" + current.sys_class_name + "&sysparm_parent_sys_id=" + current.sys_id;
}
action.setRedirectURL(url);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 06:57 AM
Hi @F_bio Santos ,
Look for Request Parent Mapping module and create mapping for problem like below:
Then try to create request from the problem with the code above (I presume you copied it from Incident), it should work. It is at least in my case.
Regards, Ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 09:03 AM
Hi @F_bio Santos ,
It seems like you're trying to accomplish two tasks:
- Redirecting the user from the "Problem" record to the Catalog homepage.
- Setting the "Parent" field of an "Incident" or "RITM" record to the number of the problem it was created from.
Let's address these tasks separately:
- Redirecting from Problem to Catalog:
Your code snippet seems generally correct for redirecting users to the catalog homepage. Ensure that sn_sc.Catalog.getCatalogCount() returns the correct count of active catalogs. Also, make sure that the URL construction is accurate for your instance.
- Setting Parent Field for Incident/RITM:
To set the Parent field of an Incident or RITM to the number of the problem it was created from, you'll need to modify the script a bit. Assuming that the Incident/RITM is being created from a Problem and the link between them is established through a field (let's say problem_id), you can achieve this by querying the Problem record and then setting the Parent field accordingly.
Here's an example of how you might do this:
// Check if the current record is an Incident or a RITM
if (current.sys_class_name == 'incident' || current.sys_class_name == 'sc_req_item') {
// Query the Problem record based on the problem_id field
var problemGr = new GlideRecord('problem');
if (problemGr.get(current.problem_id)) {
// If the Problem record is found, set the Parent field to the Problem number
current.parent = problemGr.number;
// Update the current record
current.update();
}
}
// Redirect users to the Catalog homepage
var url;
var activeCatalogsCount = sn_sc.Catalog.getCatalogCount();
if (activeCatalogsCount === 1) {
url = "catalog_home.do?sysparm_view=catalog_default";
} else {
url = "catalogs_home.do?sysparm_view=catalog_default";
}
action.setRedirectURL(url);
Make sure to replace 'problem' with the correct table name if it differs in your instance. Also, ensure that problem_id is the correct field name that links the Incident/RITM to the Problem record.
Remember to test this code thoroughly in a non-production environment before deploying it to your live instance.