making a duplicate record of a current risk assessment record at monitor stage

SK41
Giga Guru

hi,

 

i have a requirement where i have to create a copy of risk assessment record when it is at the "monitor" state.

so, for this i have created a ui action "copy" & when it is clicked it is creating the copy of that record but it is not copying the data for fields under inherent assessment, residual assements, it is skipping all the fields & directly moving to the monitor state.

i want to have a copy of all the fields in the copied assessment...is it posible to get those fields copied?

 

below is the ui action script i have written to copy all the fields but for inherent assessmnt, residual assessments, it is not getting copied.  please suggest what is the issue...

 

 

var risksc = new GlideRecord('sn_risk_advanced_risk_assessment_scope');
risksc.addQuery('entity', 'd13d985997a32110abcfb4b3f153afe7');
risksc.query();
if (risksc.next()) {
var riskGR = new GlideRecord('sn_risk_advanced_risk_assessment_instance');
riskGR.addQuery('number', 'RASMT00100009');
riskGR.query();

// Loop through the incident records and create copies with new incident numbers
while (riskGR.next()) {
var newriskGR = new GlideRecord('sn_risk_advanced_risk_assessment_instance');
newriskGR.initialize();
newriskGR.setValue('entity_1', riskGR.getValue('entity_1'));
newriskGR.setValue('risk', riskGR.getValue('risk'));
newriskGR.setValue('inherent_computed_risk_score', riskGR.getValue('inherent_computed_risk_score'));

newriskGR.setValue('summary_inherent_risk_score', riskGR.getValue('summary_inherent_risk_score'));
newriskGR.setValue('risk_response', riskGR.getValue('risk_response'));
newriskGR.setValue('state', riskGR.getValue('state'));
newriskGR.insert();
}
}

 

why the code is not copying the inherent computed field, risk response, etc?

 

3 REPLIES 3

not helping

Amit Gujarathi
Giga Sage
Giga Sage

HI @SK41 ,
I trust you are doing fine.Here's an updated version of your script that includes those fields:

 

 

 

var risksc = new GlideRecord('sn_risk_advanced_risk_assessment_scope');
risksc.addQuery('entity', 'd13d985997a32110abcfb4b3f153afe7');
risksc.query();

if (risksc.next()) {
  var riskGR = new GlideRecord('sn_risk_advanced_risk_assessment_instance');
  riskGR.addQuery('number', 'RASMT00100009');
  riskGR.query();

  // Loop through the risk assessment records and create copies with new numbers
  while (riskGR.next()) {
    var newriskGR = new GlideRecord('sn_risk_advanced_risk_assessment_instance');
    newriskGR.initialize();

    // Copy values from the original record to the new record
    newriskGR.setValue('entity_1', riskGR.getValue('entity_1'));
    newriskGR.setValue('risk', riskGR.getValue('risk'));
    newriskGR.setValue('inherent_computed_risk_score', riskGR.getValue('inherent_computed_risk_score'));
    newriskGR.setValue('summary_inherent_risk_score', riskGR.getValue('summary_inherent_risk_score'));
    newriskGR.setValue('risk_response', riskGR.getValue('risk_response'));
    newriskGR.setValue('state', riskGR.getValue('state'));

    // Copy values from the inherent assessment and residual assessments fields
    newriskGR.setValue('inherent_field1', riskGR.getValue('inherent_field1'));
    newriskGR.setValue('inherent_field2', riskGR.getValue('inherent_field2'));
    // Add more fields as needed for the inherent assessment

    newriskGR.setValue('residual_field1', riskGR.getValue('residual_field1'));
    newriskGR.setValue('residual_field2', riskGR.getValue('residual_field2'));
    // Add more fields as needed for the residual assessments

    newriskGR.insert();
  }
}

 


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



newriskGR.setValue('inherent_computed_risk_score', riskGR.getValue('inherent_computed_risk_score'));

newriskGR.setValue('summary_inherent_risk_score', riskGR.getValue('summary_inherent_risk_score'));
newriskGR.setValue('risk_response', riskGR.getValue('risk_response'));

 

these two lines are for copying the data to inherent fields but the problem is that when we copy the state field which is monitor then it copies the state to monitor but the inherent assessmnt fields disappear, they are not in the record. i have attached two screenshot, one is the record "0009" which is getting copied & other record is the copied one which does not look like original...inherent, residual& risk response tabs are missing in it...though i am copying fields through ui action..

 

what could be the issue here?