- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Using fix script same table we need to copy from one field to other field i tried with below code but it's not working let me know my mistake
var ga=new GlideRecord('sn_compliance_policy_exception');
ga.addEncodedQuery('policy=87420b0bc3ef71103cbbfb1f0501317b^cmdb_ciISEMPTY');
ga.query();
while(ga.next()){
ga.cmdb_ci=ga.user_input;
//current.name = current.u_imei_string;
ga.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi, you didn't change anything in the script I gave you right ?
For me it works fine, the record comes up in the cmdb_ci field correctly. Also one thing, you are sure right that the input provided in the user_input field is the name of the cmdb_ci item ? if the name doesn't match then the cmdb_ci wont get populated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
i checked background script it's not showing any thing
var ga=new GlideRecord('sn_compliance_policy_exception');
ga.addEncodedQuery('policy=87420b0bc3ef71103cbbfb1f0501317b^cmdb_ciISEMPTY');
ga.query();
while(ga.next()){
gs.print('the rowa'+ga.getRowCount());
var gN = new GlideRecord('cmdb_ci_pc_hardware');
gN.addQuery('name', ga.user_input);
gN.query();
if (gN.next()) {
//gs.print('the rowa'+gN.getRowCount());
ga.cmdb_ci = gN.sys_id;
ga.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The script is working perfectly fine for me.
1. Check whether the Encoded query you have given is right or not and whether it successfully picks any record or not.
2. Check whether any cmdb_ci_pc_hardware record exists with the same name which the user input field has. If not, then the scriptwont work.
For me after execution:
*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
it will only work if both the field type is same
user_input and cmdb_ci both refer to same table?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @mani55
Simply use this script:
var ga = new GlideRecord('sn_compliance_policy_exception');
// 1. Ensure the query is actually finding records
ga.addEncodedQuery('policy=87420b0bc3ef71103cbbfb1f0501317b^cmdb_ciISEMPTY');
// Optional: restrict row count for testing
// ga.setLimit(10);
ga.query();
while(ga.next()){
// 2. Ensure 'user_input' actually has data to copy
if(ga.user_input){
// 3. Make sure Workflow/Business Rules don't block this
ga.setWorkflow(false);
ga.autoSysFields(false);
// 4. Copy the value
ga.cmdb_ci = ga.user_input;
ga.update();
}
}
Happy to help! If this resolved your issue, kindly mark it as the correct answer and Helpful and close the thread so others can benefit too.
Warm Regards,
Deepak Sharma
Community Rising Star 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Kindly check my response, this working as expected for me:
(Change the field names accordingly if required)
var ga=new GlideRecord('sn_compliance_policy_exception');
ga.addEncodedQuery('policy=87420b0bc3ef71103cbbfb1f0501317b^cmdb_ciISEMPTY');
ga.query();
if (ga.next()){
var gN = new GlideRecord('cmdb_ci_pc_hardware');
gN.addQuery('name', ga.user_input);
gN.query();
if (gN.next()) {
ga.cmdb_ci = gN.sys_id;
ga.update();
}
} *************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.