- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2017 10:27 AM
Hi all,
I have a requirement where i need to populate 'Work Notes' on 'Change Request' form Affected CI's table. I am able to achieve this but i have a
problem i.e whenever i am trying to change 'State' field or do any changes on the form and save each time its creating the same set of Affected
CI's in the work notes.
Please see the below screen shot.
My code looks like below:
Business rule : Executes on 'Before' with 'Insert' and 'Update'
var look2=new GlideRecord('task_ci');
look2.addQuery('task',current.sys_id);
look2.query();
while (look2.next())
{
current.work_notes = look2.ci_item.getDisplayValue();
//look2.task = current.sys_id;
look2.update();
}
Kindly can anyone help me on this that it should not create the same record again and again each time i change something on form and update.
Thanks,
Neha
Solved! Go to Solution.
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2017 02:44 PM
Thanks for the details Neha.
You have to create an AFTER business rule on task_ci table with insert checkbox set to true and with filter condition as task starts with CHG.
This means the BR will be triggered only for change request records and with script as.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('change_request');
gr.addQuery('sys_id', current.task);
gr.query();
if(gr.next())
{
gr.work_notes = current.ci_item.getDisplayValue();
gr.update();
}
})(current, previous);
Please let me know if you have any questions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2017 10:40 AM
Hi Neha,
You need to remove the condtion from when to run if any and add condition under advanced tab as below.
current.state.changesTo(3) //Replcae 3 with the value of state on which you want to update the record.
Hope this helps.
Regards
Ujjawal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2017 10:40 AM
Hi Neha,
Is the BR written on parent table which copying down the comments to its child?
or maybe I think in the task_ci table there are two records of ci for the same task, check that. use if then..
And I would also request you to remove the current.update(); part on BR.
Regards,
Shariq
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2017 10:47 AM
Hi Ujjwal,
I do not have any specific condition like State the it should trigger. In general if am changing something on form and save its creating new records in work notes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2017 10:49 AM
Hi Sharique,
I have written this on Parent table i.e 'Change Request' . It has child table 'Affected CI' .I am populating the Affected CI's into The Work Notes i.e from child to parent. Also if i remove current.update() still no luck its behaving the same way.
Thanks,
Neha

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2017 11:25 AM
Hello Neha,
Don't use using current.update(); in BEFORE business rule to avoid performance issue. So you mean this BR is triggered every time you update the changes on form?
If yes can you please share the condition filter(screenshot) of the BR.