Redirect to the incident record in the Service Operations Workspace, created for the case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I need to respond to this request and make these changes to the Record Producer Create Incident script. I created the vuri variable, and the code is working up to option b. However, I can't do what you ask for in option c.
Could someone please help me?
Update the "Create Incident" record producer.
- Create a new hidden variable on the Record producer called vURI, with a default value of "javascript:gs.action.getGlideURI().toString()" (Note: This will identify the portal used to bring in the record producer.
- Update the script for the record producer:
- At the start of the script add a new variable to pull the hidden variable from the producer into the script and another to state if this is from the portal as true/ false. look to see if the string from the portal URI contains the business_portal sys_id. If it does set the second variable to true.
- Replace the current 2nd line (current.contact_type='web';) to be an if statement:
if (<from portal variable> == true) then current.contact_type='web' else current.contact_type='phone'
- Add a new redirect to the end of the script based on the variable created in step a. If the record is created in the portal we need to direct the user to the Case record as normal. Else redirect to the incident record in the Service Operations Workspace, created for the case. Note: You may have to have a pause in the script to allow for the creation of the incident record via the flow.
Record producer script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12m ago
Hi @Maria Lucia da , The Record Producer script won't work because it will not be able to find any record as the query is having an empty condition.. Here replace this with the code given below.
Script -
// Step A: Get URI and detect if it's from the portal
var uri = producer.vuri.toString();
gs.info('URI value: ' + uri);
var isPortal = (uri.indexOf('f264dbaccbfd52108d3f6a6fc041e4b5') > -1); // business_portal sys_id
gs.info('Is portal: ' + isPortal);
// Step B: Set contact type
current.state = 1;
if (isPortal) {
current.contact_type = 'web';
} else {
current.contact_type = 'phone';
}
current.priority = producer.priority;
// Partner logic
var accountId = gs.getUser().getCompanyID();
if (current.account != accountId) {
var account = new GlideRecord("customer_account");
if (account.get(accountId) && account.partner) {
current.partner_contact = gs.getUserID();
current.partner = gs.getUser().getCompanyID();
}
}
// Service organization
if (!gs.nil(producer.deployed_item) && !gs.nil(producer.deployed_item.service_organization)) {
current.requesting_service_organization = producer.deployed_item.service_organization;
}
// HTML description
if (producer.html_description && producer.html_description != '')
current.comments = '[code]' + producer.html_description + '[/code]';
// Step C: Redirect logic
if (isPortal) {
// ✅ Redirect to Case record (normal)
producer.redirect = current;
} else {
// 🕒 Add short pause to allow Flow to create Incident
gs.sleep(3000); // wait 3 seconds
// Find related Incident
var grIncident = new GlideRecord('incident');
grIncident.addQuery('u_case', current.getUniqueValue()); // <-- Replace 'u_case' with your actual reference field
grIncident.query();
if (grIncident.next()) {
// ✅ Redirect to Incident in SOW
producer.redirect = 'nav_to.do?uri=/now/sow/record/incident/' + grIncident.getUniqueValue();
} else {
gs.info('No related incident found for case: ' + current.number);
}
}
Try this and let me know.
If this answer helps you in any way, Mark this as accepted solution and give a thumbs up as this will help me and other readers as well.
Regards,
Saurabh V.