Creation of auto problem record is missing few fields with current.getUniqueValue

roshini1
Kilo Guru

Hi Team,
am writing the below before BR in incident table for creating a problem record for inc which moves to resolved state, am able to get the problem record creation, but first reported by(field inside problem record) and problem id( field inside inc record) is not getting mapped. The same code is working in my PDI, but not in my dev instance.(highlighted code in red is not working in dev instance but working in my pdi)
Can someone please suggest the modifications that is required

var prbGR = new GlideRecord("problem");
prbGR.initialize();
prbGR.description = current.description;
prbGR.short_description = current.short_description;
prbGR.cmdb_ci = current.cmdb_ci;
prbGR.impact = current.impact;
prbGR.urgency = current.urgency;
prbGR.priority = current.priority;
prbGR.company = current.company;
prbGR.business_service = current.business_service;
prbGR.service_offering = current.service_offering;
prbGR.sys_domain = current.sys_domain;
prbGR.first_reported_by_task = current.getUniqueValue();
prbGR.insert();
current.problem_id = prbGR.sys_id;
gs.addInfoMessage(gs.getMessage("Problem {0} created", prbGR.number));
action.setRedirectURL("incident.do?sys_id=" + current.sys_id.toString());

1 ACCEPTED SOLUTION

Thank you so much for investing time on this. I found the issue. It was with setting the display value to true for a different field in the problem table instead of number field. Once the change is made to the table level columns the issue got resolved.

View solution in original post

7 REPLIES 7

sushantmalsure
Mega Sage
Mega Sage

Hi @roshini1 

What is current here? like are you running this BR but on which table?

first_reported_by_task is this a field referencing to task table?

Is this BR runs after or before update?

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

What is current here? like are you running this BR but on which table?
the bR is running in incident table, so current in incident table fields

first_reported_by_task is this a field referencing to task table?
it's in problem record

Is this BR runs after or before update?
it's a before BR

ok new questions.

I know 'first_reported_by_task' is from problem but is it referencing to task table ? 

if Yes, the try using following instead of 'prbGR.first_reported_by_task = current.getUniqueValue();':

 

prbGR.first_reported_by_task = current.sys_id;

 

This BR runs before, then insert or update ?

this should not before insert as you are tying to access the sys_id which may not be created before inserting. so, have it after insert/update .

and test it again with following final script in after insert BR

 

var prbGR = new GlideRecord("problem");
prbGR.initialize();
prbGR.description = current.description;
prbGR.short_description = current.short_description;
prbGR.cmdb_ci = current.cmdb_ci;
prbGR.impact = current.impact;
prbGR.urgency = current.urgency;
prbGR.priority = current.priority;
prbGR.company = current.company;
prbGR.business_service = current.business_service;
prbGR.service_offering = current.service_offering;
prbGR.sys_domain = current.sys_domain;
prbGR.first_reported_by_task = current.sys_id; // this field 'first_reported_by_task' should be referencing to incident/task
var newPRB= prbGR.insert();
current.problem_id = newPRB;
current.update();
gs.addInfoMessage(gs.getMessage("Problem {0} created", prbGR.number));
action.setRedirectURL("incident.do?sys_id=" + current.sys_id.toString());

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Thank you so much for investing time on this. I found the issue. It was with setting the display value to true for a different field in the problem table instead of number field. Once the change is made to the table level columns the issue got resolved.