- 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
Hi @mani55 - Where is user_input coming from? I would have serious reservations about matching on text input since CI names aren't necessarily unique, but technically something like this should work:
// Instantiate GlideRecord
var ci = new GlideRecord("cmdb_ci");
// Get the name of the display field
var ciDisplayName = ci.getDisplayName();
var policyException = new GlideRecord('sn_compliance_policy_exception');
policyException.addEncodedQuery('policy=87420b0bc3ef71103cbbfb1f0501317b^cmdb_ciISEMPTY');
policyException.query();
while (policyException.next()) {
// Query cmdb_ci for a match
if (ci.get(ciDisplayName, policyException.getValue('user_input'))) {
// If there's a match, set cmdb_ci
policyException.cmdb_ci = ci.getUniqueValue();
policyException.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
i tried with below script but it's not working
// Instantiate GlideRecord
var ci = new GlideRecord("cmdb_ci_pc_hardware");
// Get the name of the display field
var ciDisplayName = ci.getDisplayName();
var policyException = new GlideRecord('sn_compliance_policy_exception');
policyException.addEncodedQuery('policy=87420b0bc3ef71103cbbfb1f0501317b^cmdb_ciISEMPTY');
policyException.query();
while (policyException.next()) {
// Query cmdb_ci for a match
if (ci.get(ciDisplayName, policyException.getValue('user_input'))) {
// If there's a match, set cmdb_ci
policyException.cmdb_ci = ci.getUniqueValue();
policyException.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@mani55 Could you please clarify which field you want to populate from which. User input value from cmdb_ci or vice versa.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
we have this two fields like cmdb_ci field and user input we have in sn_compliance_policy_exception table . already we have value in user_input table and it's string field . cmdb_ci is refrence field and it's refereing cmdb_ci_pc_hardware table what we need is we need copy from user_input to cmdb_ci field in sn_compliance_policy_exception table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @mani55 ,
Please try the below script, it's working 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.