Trying to setting category from a record producer

Ryan Bader
Tera Contributor

Im trying to set my category field on the incident form based on a variable collected from the record producer. the following is what i currently have, but it is only setting to the default. 

var isMobile = GlideMobileExtensions.getDeviceType() == 'm';
var link = isMobile ? '#/!list/incident/q:active=true%5Ecaller_id=javascript:gs.user_id()%5EEQ' : 'home.do';

var linkLbl = isMobile ? "List" : "Homepage";
var br = '<br/>';
var linkURL = '<a href="' + link + '">' + gs.getMessage(linkLbl) + '</a>';
var msgArgs = [br, linkURL];

var callerSysID = gs.getUserID();
var parent_table = RP.getParameterValue('sysparm_parent_table');
if (JSUtil.notNil(parent_table)) {
    var parent_map = new GlideRecord('request_parent_mapping');
    parent_map.addQuery('parent_table', parent_table);
    parent_map.query();
    if (parent_map.next())
        var requested_for_field = parent_map.getValue('requested_for_field');
    var parentGR = new GlideRecord(parent_table);
    parentGR.addQuery('sys_id', RP.getParameterValue('sysparm_parent_sys_id'));
    parentGR.query();
    if (parentGR.next())
        callerSysID = parentGR.getValue(requested_for_field);
}

var callerGR = new GlideRecord('sys_user');
callerGR.get(callerSysID);
var callerDV = callerGR.getDisplayValue();

//set service and service offering
current.contact_type = 'self-service';
current.caller_id = callerSysID;
current.business_service='377d075ec3c40610618d1fb4e4013126'; //377d075ec3c40610618d1fb4e4013126 = 'ATM/ITM' service
current.service_offering = '445ecb5ec3c40610618d1fb4e40131eb'; // 445ecb5ec3c40610618d1fb4e40131eb = 'ATM/ITM' offering

//Set Description
var descriptionStr = producer.cmdb_ci.name;
descriptionStr += " at location " + producer.cmdb_ci.location.name;
descriptionStr += " has and issue of " + producer.issue_descriptions;
current.short_description = descriptionStr;


//Set Assignment Group
current.assignment_group = "9ac98878c326b150618d1fb4e4013134"; //9ac98878c326b150618d1fb4e4013134 = Cash Delivery Systems
// Set Category (server-side)
var selectedIssue = producer.issue_descriptions;
switch (selectedIssue) {
    case 'ATM Side':
    case 'Audio':
    case 'Audio/Video':
    case 'Black Screen':
    case 'Frozen Session':
    case 'Lost Comms':
    case 'Offline':
    case 'Session Closed Unexpectedly':
    case 'Session Froze':
        // Set the Category field value to 'connectivity'
        current.category = 'connectivity';
        break;

    case 'Project - Professional Services':
        // Set the Category field value to 'database'
        current.category = 'database';
        break;

    default:
        // Optionally, set a default category or handle other cases
        current.category = 'Communication'; // or any default value
        break;
}
var incRPUtil = new LinkRecordProducerToIncident();
incRPUtil.linkRecordProducerToParentIncident(RP.getParameterValue('sysparm_parent_sys_id'), current);

also her is a screen shot of the choices for the issue_descriptions variable

RyanBader_0-1729112349862.png

 

 

 

1 ACCEPTED SOLUTION

Anish Singh
Tera Expert

Can you add toString() and see if it works?

var selectedIssue = producer.issue_descriptions.toString();

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

The first thing I would do is log selectedIssue before the switch to confirm its value.

Anish Singh
Tera Expert

Can you add toString() and see if it works?

var selectedIssue = producer.issue_descriptions.toString();