The CreatorCon Call for Content is officially open! Get started here.

concept on g_scratchpad

Rajkumar Bommal
Tera Contributor

Hi 
How would i Show Alert message on creating an incident record it should display the caller's location. By using g_scratchpad in BusinessRule and client script..

1 ACCEPTED SOLUTION

@Rajkumar Bommal - ah apologies, it was the caller's location not the current user.😅

 

If so, you can update the BR to 

(function executeRule(current, previous /*null when async*/ ) {

    var userGr = new GlideRecord("sys_user"); 
    userGr.get(current.getValue('caller_id'));
    g_scratchpad.currentLocation = userGr.getDisplayValue('location');

})(current, previous);

View solution in original post

18 REPLIES 18

Rajkumar Bommal
Tera Contributor

I updated my Profile location i.e., in system admin now its showing sys admin location only
Not the location of the caller that i have selected 

RajkumarBommal_0-1711622233723.png

 

@Rajkumar Bommal - ah apologies, it was the caller's location not the current user.😅

 

If so, you can update the BR to 

(function executeRule(current, previous /*null when async*/ ) {

    var userGr = new GlideRecord("sys_user"); 
    userGr.get(current.getValue('caller_id'));
    g_scratchpad.currentLocation = userGr.getDisplayValue('location');

})(current, previous);

Thank You so much for the support to you all guys @James Chun @1__AnithaHV @Pushpanjali @Maddysunil 

RajkumarBommal_0-1711622943612.png

 

Maddysunil
Kilo Sage

@Rajkumar Bommal 

Display BR:

 

(function executeRule(current, previous /*null when async*/) {
    // Fetch the caller's location
    var caller = current.getValue('caller_id');
    if (caller) {
        var location = caller.location.getDisplayValue();
        gs.info("Caller's Location: " + location);
        // Store the caller's location in g_scratchpad
        current.u_callers_location = location; // Store in a field
        gs.scratchpad.caller_location = location; // Store in g_scratchpad
    }
})(current, previous);

 

Client Script:

 

(function() {
    var callerLocation = g_scratchpad.caller_location;
    if (callerLocation) {
        alert("Caller's Location: " + callerLocation);
    }
})();

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks