In API there are sending value so how to convert that value to sys_id

mani55
Tera Contributor

i created one API so that api needs to check valid to date and we need to make active false that record based on user_input field .actually i have one query in API there sending value but in table that field is sys_id so how we can convert to value to sys_id i tried below script but it won't working so please help me on this

var userinput='LNL-5CG4090Q0P';
var currentTime = gs.nowDateTime();
var gr=new GlideRecord('sn_compliance_policy_exception');
gr.addQuery('active=true');
gr.addQuery('user_input.name',userinput);
gr.addQuery('valid_to', '<=', currentTime ); // 
gr.setLimit('1');
gr.query();
if(gr.next()){
	gr.active='false';
	gr.u_early_closure_reason='closed by automation';
	gr.u_functional_area_name_application_asset_etc='test';
	gr.update();
}
1 ACCEPTED SOLUTION

svirkar420
Giga Guru

Hi @mani55 , Try below script and let me know if this works.

var userinput = 'LNL-5CG4090Q0P';
var currentTime = gs.nowDateTime();

var refGR = new GlideRecord('cmdb_ci');
refGR.addQuery('name', userinput);
refGR.query();

if (refGR.next()) {
var userSysId = refGR.getUniqueValue();
var gr = new GlideRecord('sn_compliance_policy_exception');
gr.addQuery('active', true);
gr.addQuery('user_input', userSysId);
gr.addQuery('valid_to', '<=', currentTime);
gr.setLimit(1);
gr.query();
if (gr.next()) {
gr.active = false;
gr.u_early_closure_reason = 'closed by automation';
gr.u_functional_area_name_application_asset_etc = 'test';
gr.update();
}
}

 

If this solution helped you Please Mark this solution as accepted and helpful as it will be helpful for other users as well.
Best Regards.
Saurabh V.

View solution in original post

2 REPLIES 2

svirkar420
Giga Guru

Hi @mani55 , Try below script and let me know if this works.

var userinput = 'LNL-5CG4090Q0P';
var currentTime = gs.nowDateTime();

var refGR = new GlideRecord('cmdb_ci');
refGR.addQuery('name', userinput);
refGR.query();

if (refGR.next()) {
var userSysId = refGR.getUniqueValue();
var gr = new GlideRecord('sn_compliance_policy_exception');
gr.addQuery('active', true);
gr.addQuery('user_input', userSysId);
gr.addQuery('valid_to', '<=', currentTime);
gr.setLimit(1);
gr.query();
if (gr.next()) {
gr.active = false;
gr.u_early_closure_reason = 'closed by automation';
gr.u_functional_area_name_application_asset_etc = 'test';
gr.update();
}
}

 

If this solution helped you Please Mark this solution as accepted and helpful as it will be helpful for other users as well.
Best Regards.
Saurabh V.

@mani55 , Thanks for marking this solution as accepted can you please mark it helpful and close the thread as it will be helpful for others as well. appreciate it.

Best regards,

Saurabh V.