Dotwalking in a script include

gunishi
Tera Guru

Hi there, 

 

So sorry for the vagueness, having to omit company data.

 

If I have a field on the form, let's say 'name', can I pass this info into a function in a script include and then dotwalk from it? For example:

exampleFunc : function(name){
    approver = name.contacts.approver

}

 

If this would not work, do I need to use a query and then dotwalk from there? Many thanks!

 

Kind regards, 

G

 

5 REPLIES 5

Peter Bodelier
Giga Sage

Hi @gunishi,

 

Your second option is the way to go.

So pass the sys_id of the record, and retrieve it in the script include.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

OlaN
Giga Sage
Giga Sage

Hi,

Yes you probably can. Based on the given information, I would suggest doing a GlideAjax call to retrieve some data from the server depending on variables/fields on the Form.

Check this article to get started with GlideAjax.

 

Community Alums
Not applicable

Well you can pass the entire object - lets say from business rule you call your script include named DoDotwalk() :

 

new DoDotwalk().startDotwalking(current, <YOUR REFERENCE FIELD ON CURRENT>, <THE FIELD YOU NEED ON REF TABLE>)

 

where in your SI startDotwalking is something like:

 

startDotwalking: function(obj, refField, retfld){
    var refObject = obj[refField].getRefRecord();
     return refObject[retfld];
}

This way you can reuse it on other places as you dynamically pass the reference field and the field you want to return from the referenced table.

You can also update the referenced record by simply doing:

var refObject = obj[refField].getRefRecord();

refObject.description = "New description";

refObject.update()

 

Yet be careful how you use it as there might be other dependencies and you can trigger extra logic you might not want to have.

 

Community Alums
Not applicable

So to use it on incident table and get from assigned to field company assigned to this user you should call it like:

var userCompany = new DoDotWalk().startDotwalking(current, 'assigned_to', 'company');
gs.addInfoMessage(userCompany + "");