"Previous" Object in Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2018 01:13 PM
We have a requirement to add all assignees for associated Change Tasks to the CAB meeting for related Changes.
I believe that I can add the code to implement this requirement by overriding the "refreshAttendees" method (shown below) from the "CABAgendaItemSNC" Script Include in its extended "CABAgendaItem" class.
There is one thing I do not seem to understand about the script though. How can "previous" be in scope for an instantiated "CABAgendaItem" object? Until I understand this, I do not want to make any modifications.
I know "previous" & "current" are available objects in Business Rules and UI Actions, but I would have thought that they would be out of scope with in a Class (unless they were passed as a parameter).
Thanks in advance.
refreshAttendees: function() {
if (!this._gr || !this._gr.getUniqueValue())
return;
var gotPrevious = false;
if (previous != null && previous.getUniqueValue() == this._gr.getUniqueValue())
gotPrevious = true;
for (var i = 0; i < CABAgendaItem.TASK_FIELDS_FOR_ATTENDEES.length; i++) {
var fieldName = CABAgendaItem.TASK_FIELDS_FOR_ATTENDEES[i];
if (gotPrevious && !previous.task[fieldName].nil())
this.removeAttendee("" + previous.task[fieldName]);
if (!this._gr.task[fieldName].nil())
this.addAttendee("" + this._gr.task[fieldName]);
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2018 10:06 PM
This works explicitly even if you do not pass the current and previous object to script include if it function is getting called from busienss rule who have access to current and previous object.
You can find similar configuration in certain inbound email actions scripts as well which calls some script include and without even passing the email or current object as parameter, script include understands it.
From config point of view, current and previous looks like global variables in the context of the record and transaction.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2018 10:20 AM
Thanks for the response Deepak.
One of the points of entry to the "CABAgendaItem.refreshAttendees" method call is through the "Refresh Agenda Items" UI Action in the "cab_meeting" Default form view.
The UI Action instantiates a "CABMeeting" object, and calls some methods which eventually instantiate a "CABAgendaItem" object that calls the "refreshAttendees" method.
Would you know what value the "previous" object in the "CABAgendaItem.refreshAttendess" method would have in this case? Would it be a "cab_meeting" GlideRecord or Null or something else? I wouldn't think that it would be a "cab_agenda_item" GlideRecord, but maybe I'm mistaken.
Thanks again for helping gain an understanding of system behavior.