unable to update record through record producer

Swati k1
Tera Contributor

Hi All,

I'm using below code to insert or update existing record trough record producer , but its not working as expcted .either not created or not updating also 

please help me on this.

* i checked few community posts which were not helpd ...kindly elp me on this code

 

 

// to update existing record


if (producer.type_of_request == 'existing') {
var record = producer.name;
gs.log(record, 'test11')
var review = new GlideRecord('cmdb_ci_service');
review.addQuery('sys_id', record);
review.query();
gs.log(review.getRowCount(), 'testrow')
if (review.next()) {
// review.name = producer.application_name1;
review.spm_service_portfolio = producer.spm_service_portfolio;
review.business_relation_manager = producer.business_relation_manager;
review.update();
gs.log('test12', 'teste')
gs.addInfoMessage("The record has now been updated");
current.setAbortAction(false);
}
current.setAbortAction(true);


} else if (producer.type_of_request == 'new') {
var newRec = new GlideRecord("cmdb_ci_service");
newRec.initialize();
newRec.name = producer.application_name1;
newRec.spm_service_portfolio = producer.spm_service_portfolio;
newRec.business_relation_manager = producer.business_relation_manager;
newRec.insert();
}

2 REPLIES 2

reshmapatil
Tera Guru

Hi @Swati k1 ,

Are you getting logs?

Else if loop looks correct.

In If loop,

Which type of name variable is and what value you are putting?

var record = producer.name;

review.addQuery('sys_id', record); // you are comparing name with sys_id

 

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**

jaheerhattiwale
Mega Sage
Mega Sage

@Swati k1 Please update the code as below and try.

 

if (producer.type_of_request == 'existing') {
var record = producer.name;
var review = new GlideRecord('cmdb_ci_service');
review.addQuery('sys_id', record); //check if record is sys_id or not
review.query();

if (review.next()) {
// review.name = producer.application_name1;
review.spm_service_portfolio = producer.spm_service_portfolio;
review.business_relation_manager = producer.business_relation_manager;
review.update();
gs.addInfoMessage("The record has now been updated");
}

current.setAbortAction(true);
} else if (producer.type_of_request == 'new') {
current.name = producer.application_name1;
current.spm_service_portfolio = producer.spm_service_portfolio;
current.business_relation_manager = producer.business_relation_manager;
}
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023