copying field from case to incident

yunus shadman
Tera Contributor

i have a requirement to copy the field (category) from case to incident . i have written a BR for that 

(function executeRule(current, previous /*null when async*/ ) {
    var caseCP = new GlideRecord("incident");
     caseCP.addQuery("sys_id", current.incident);
    caseCP.query();
    if (caseCP.next()); {
        caseCP.u_asset = current.asset;
        caseCP.u_product = current.product;
        caseCP.category = current.category.toString();
        caseCP.impact = current.impact;
        caseCP.urgency = current.urgency;
        caseCP.contract = current.contract;
        caseCP.u_entitlement = current.entitlement;
        caseCP.u_ci_service_level = current.u_ci_service_level;
        caseCP.description = current.description;
        caseCP.short_description = current.short_description;
        caseCP.update(); //updates change
    }
})(current, previous);

 

 

but for category field it is showing string value in incident form instead of string value, i check for the category dictionary , it is showing type as integer in case form and integer in the incident form . how can i copy the field ..? 

 

5 REPLIES 5

Aman Kumar S
Kilo Patron

I would suggest to use getValue and setValue instead of dotwalking to fetch the field values, try to update using the same it would work. Also, you have to ensure, backend value of choices in case and incident are same .

code eg:

 caseCP.setValue("category",  current.getValue("category");

Best Regards
Aman Kumar

actually i am facing issue for the category field only , it is set as type= integer  for the case choice list , and type = string for the incident choice list. and i didnt have permission to change the out of the box configuration , so how can i copy that category field from case to incident .? i have already checked multiple times but it is either creating duplicate choice list in incident or it is showing the backed value (integer) of the case choice list in the incident form  . i am a beginner for programming and servicenow . help me to find out the solution   

Community Alums
Not applicable

Hi @yunus shadman ,

Refer to this KB from ServiceNow, it should help you:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0817494

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep