unable to update record through record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2022 12:26 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2022 12:46 PM
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**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2022 11:20 PM
@Swati k1 Please update the code as below and try.
ServiceNow Community Rising Star, Class of 2023