Creating History Line record for a User

Wasim Akhtar
Tera Expert
Tera Expert

Hi,

 

I am trying to create a custom history line record for User (Sys ID mentioned as XYZ) via a script.

The script doesn't seem to be working.

I do understand that i cannot set value like below but don't know the solution.

history.set.id='XYZ'; 

Any suggestions

 

 

var historySet = new GlideRecord('sys_history_set');
historySet.addQuery('id', 'XYX');
historySet.query();
if (historySet.next())

{

var history = new GlideRecord('sys_history_line');
history.initialize();
history.set.id='XYZ';
history.field='Role Optimization';
history.type='relation';
history.label='relation';
history.relation='Role Optimization';
history.old='User Removed from Groups ';
history.insert();

}

1 ACCEPTED SOLUTION

Pratik Malviya
Tera Guru

Hi @Wasim Akhtar ,

 

Can you try below,

var historySet = new GlideRecord('sys_history_set');
historySet.addQuery('id', 'XYX');
historySet.query();
if (historySet.next())

{

var history = new GlideRecord('sys_history_line');
history.initialize();
//history.set.id='XYZ';

history.set = historySet.getUniqueValue(); // This will return XYZ or you can use historySet.getValue('sys_id');
history.field='Role Optimization';
history.type='relation';
history.label='relation';
history.relation='Role Optimization';
history.old='User Removed from Groups ';
history.insert();

 

 

Please mark correct it it helps.

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks,
Pratik Malviya

View solution in original post

2 REPLIES 2

Pratik Malviya
Tera Guru

Hi @Wasim Akhtar ,

 

Can you try below,

var historySet = new GlideRecord('sys_history_set');
historySet.addQuery('id', 'XYX');
historySet.query();
if (historySet.next())

{

var history = new GlideRecord('sys_history_line');
history.initialize();
//history.set.id='XYZ';

history.set = historySet.getUniqueValue(); // This will return XYZ or you can use historySet.getValue('sys_id');
history.field='Role Optimization';
history.type='relation';
history.label='relation';
history.relation='Role Optimization';
history.old='User Removed from Groups ';
history.insert();

 

 

Please mark correct it it helps.

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks,
Pratik Malviya

Wasim Akhtar
Tera Expert
Tera Expert

thanks for your help @Pratik Malviya