Get Impact and Urgency values from JSON

Wyatt Fudal1
Tera Guru

Hello,

 

I'm running into issue getting the Impact and Urgency field value. My code is not working. I think I did something wrong with my code. 

JSON Data

23T20:33:41Z","Subcategory":"Other","CustomerImpact":"No","Description":"TEST","BusinessImpact":"TEST","WatchList":[],"WatchList@odata.type":"#Collection(Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser)","WatchList#Claims":[],"WatchList#Claims@odata.type":"#Collection(String)","Impact":"Low","Urgency":"High","Queued":false,"Modified":"2024-04-

My code

function getImpactID(impactValue){
    var impactValue = new GlideRecord ('impact');
    impactValue.addQuery('value', impactValue);
    impactValue.query();
    if(impactValue.next()) {
        return impactValue.sys_id;
    }
}

function getUrgency(_urgencyValue){
    var urgencyValue= new GlideRecord ('urgency');
    urgencyValue.addQuery('value', urgencyValue);
    urgencyValue.query();
    if(urgencyValue.next()) {
        return urgencyValue.sys_id;
    }
   
   
}
1 ACCEPTED SOLUTION

Wyatt Fudal1
Tera Guru

I able to get it to by doing this, thank you all for the help!!

function levelStringToNumber(value) {
    switch (value) {
        case "High":
            return 1;
       
        default:
        case "Medium":
            return 2;

        case "Low":
            return 3;
    }
}

View solution in original post

7 REPLIES 7

Sandeep Rajput
Tera Patron
Tera Patron

@Wyatt Fudal1 From where are you getting the JSON data? is it via a web-service/API?

Web Service. so the code is in inbound record. Everything works in the code except the impact and urgency 

Full code

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier){
    var email_data = email.body_text;

    var lookText = "JSON DATA";
    var index1 = email_data.indexOf(lookText);
   
    var descData = email_data.substring(0, index1).trim();
    var jsonData = email_data.substring(index1 + lookText.length).trim();

    var newLineIndex = jsonData.indexOf("\n");
    if (newLineIndex >= 0) {
        jsonData = jsonData.substr(0, newLineIndex).trim();
    }
   
    var parsed = JSON.parse(jsonData);  
   
    //get caller information
    current.caller_id = getUserId(parsed.RequestedBy.Email);
   
    //Get Watchlist Data
    var watchListData = parsed.WatchList;
    var watchListIds = [];
    for(var i = 0; i < watchListData.length; i++){
        gs.info(watchListData[i].Email);
        watchListIds.push(getUserId(watchListData[i].Email));
    }
    current.watch_list = watchListIds.join(',');
   
    //Get Configuration Item    
    current.cmdb_ci= getCMDBId(parsed.Configuration_x0020_Item);                        
   
    current.description = descData;
    current.insert();

})(current, event, email, logger, classifier);

function getUserId(userEmailId)
{
    var userRecord = new GlideRecord('sys_user');
    userRecord.addQuery('email', userEmailId);
    userRecord.query();
    if (userRecord.next()) {
        return userRecord.sys_id;
    }
}

function getCMDBId(cmdbValue){
    var cmdbRecord = new GlideRecord('cmdb_ci');
    cmdbRecord.addQuery('name', cmdbValue);
    cmdbRecord.query();
    if (cmdbRecord.next()) {
        return cmdbRecord.sys_id;
    }
}

function getImpactID(impactValue){
    var impactValue = new GlideRecord ('impact');
    impactValue.addQuery('value', impactValue);
    impactValue.query();
    if(impactValue.next()) {
        return impactValue.sys_id;
    }
}

function getUrgency(_urgencyValue){
    var urgencyValue= new GlideRecord ('urgency');
    urgencyValue.addQuery('value', urgencyValue);
    urgencyValue.query();
    if(urgencyValue.next()) {
        return urgencyValue.sys_id;
    }
   
   
}



Hello @Wyatt Fudal1,

 

Please modify your impact and urgency functions and try once.

 

 

function getImpactID(impactValue) {
    var impactGR = new GlideRecord('impact');
    impactGR.addQuery('value', impactValue); 
    impactGR.query();
    if (impactGR.next()) {
        return impactGR.sys_id;
    }
}

function getUrgency(urgencyValue) {
    var urgencyGR = new GlideRecord('urgency');
    urgencyGR.addQuery('value', urgencyValue); // Here is an error before in your script
    urgencyGR.query();
    if (urgencyGR.next()) {
        return urgencyGR.sys_id;
    }
}

 

 

Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.

Sadly that did not work. Would there be another to parse the data from the JSON?