when incident priority is p5 , problem priority is also same ,but need to change.

surya65
Tera Contributor

Hi Team,

i have incident priority are: 1 to 5.

problem priority are :1 to 4.

when i  cretaed the incident with priority p5, and i created the problem through incident ,and 

priority of the problem is same has incident p5.

but in the problem form, under priority drop down i have 1 - 4, 

soo need to change when the incident  priority is p5, when problem priority should be p4. only.

in my case its showing p5. 

how can i achive this any helps,

thanks,

surya.

20 REPLIES 20

Sourabh26
Giga Guru

Hi,

 

You can achieve this using BR

 

BR - After (Insert/Update)

Table - Incident

 

/*
Condition 
priority changes P5
*/

//Script

var grProb = new GlideRecord('problem');
if(grProb.get('incident',current.number));//problem table incident field name
{
  grProb.setValue('priority','P4');//problem priority
  grProb.update();
}

 

Mark this as Helpful/Correct, if Applicable.

 

Regards,

Sourabh

i try this but when i select the incident priority is p5 and after that i creating the problem throug incident same priority talking. p5 only 

 

Pedro Grilo1
Mega Sage

Hi,

 

To change the way the problem creation works you will need to adjust the "getProblemFromIncident" on "global.IncidentUtils" script include.

Probably better to have a business rule on INSERT to problem and change the priority to 4 in case it is being set as 5.

 

I hope it helps!

Pedro

shloke04
Kilo Patron

 

Hi Surya,

Couple of points to note here:

1) Priority is a Field present on Task Table so by default OOB it will have Priority 5 as a choice both in Incident and Problem Table and hence it is getting mapped.

Can you show me the choice list of your Priority field on Problem form?

Ideally, you should not be requiring any script here.

But still if you need to do it then the ideal way will be to modify the UI Action named as "Create problem" itself.

UI Action link below:

https://instance.service-now.com/nav_to.do?uri=sys_ui_action.do?sys_id=2f43c471c0a8006400a07440e49924c2

Replace "instance' with your instance name.

Now within this UI Action there is a Script Include named as "IncidentUtils" is called which calls the method "getProblemFromIncident" which is a Read Only method and best practice here would be to override this method as per steps shown below:

Link for Script Include which you need to update:

https://instance.service-now.com/nav_to.do?uri=sys_script_include.do?sys_id=87e5e796531232000600e26b88dc3478

Replace "instance' with your instance name.

Updated Script Include to be used :

var IncidentUtils = Class.create();
IncidentUtils.prototype = Object.extendsObject(IncidentUtilsSNC, {
    initialize: function() {
        IncidentUtilsSNC.prototype.initialize.call(this);
    },
    /***************Custom changes****************/
    getProblemFromIncident: function(current) {
        if (!current.isValidRecord())
            return undefined;

        var prob = new GlideRecord("problem");
        var defaultCreateFromIncidentPropVal = 'number,description,short_description,cmdb_ci,impact,urgency,priority,company,sys_domain,business_service,service_offering';
        var createFromIncidentPropVal = gs.getProperty('com.snc.problem.create_from_incident.attributes', defaultCreateFromIncidentPropVal);
        var fieldsToBeCopiedFromIncident = this.getCsvValue(createFromIncidentPropVal);

        for (var i = 0; i < fieldsToBeCopiedFromIncident.length; i++) {
            if (fieldsToBeCopiedFromIncident[i] === 'number') {
                if (prob.isValidField("first_reported_by_task"))
                    prob.first_reported_by_task = current.getUniqueValue();

            } else if (fieldsToBeCopiedFromIncident[i] === 'priority') {
                if (prob.isValidField("priority")) {
                    if (current.priority == 4 || current.priority == 5) {
                        prob.priority = 4;
                    } else {
                        prob.priority = current.priority;
                    }
                }

            } else if (fieldsToBeCopiedFromIncident[i] === 'category') {
                var elCategory = prob.getElement("category");
                var choicesCategory = elCategory.getChoices();
                if (choicesCategory && choicesCategory.indexOf(current.category) >= 0)
                    prob.category = current.category;

            } else if (fieldsToBeCopiedFromIncident[i] === 'subcategory') {
                var elSubcategory = prob.getElement("subcategory");
                var choicesSubcategory = elSubcategory.getChoices(current.category);
                if (choicesSubcategory && choicesSubcategory.indexOf(current.subcategory) >= 0)
                    prob.subcategory = current.subcategory;

            } else if (prob.isValidField(fieldsToBeCopiedFromIncident[i])) {
                prob[fieldsToBeCopiedFromIncident[i]] = current[fieldsToBeCopiedFromIncident[i]];

            } else {
                gs.addErrorMessage(gs.getMessage("{0} is not a valid field in Problem", fieldsToBeCopiedFromIncident[i]));
                return undefined;
            }
        }
        return prob;
    },

    getCsvValue: function(val) {
        val = val.trim().split(',');
        for (var i = 0; i < val.length;) {
            val[i] = val[i].trim();
            if (!val[i]) {
                val.splice(i, 1);
            } else {
                i++;
            }
        }
        return val;
    },



    type: 'IncidentUtils'
});

IncidentUtils.isCopyIncidentEnabled = function(current) {
    var incidentUtils = new IncidentUtils();
    return incidentUtils.isCopyIncidentFlagValid();

};

IncidentUtils.isCreateChildIncidentEnabled = function(current) {
    var incidentUtils = new IncidentUtils();
    return incidentUtils.isCreateChildIncidentFlagValid();

};

 

This should work for you. Let me know if you are stuck.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke