Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Sending data from server to client

Rosy14
Kilo Sage

In below widget I want to send data to client side. Its not working

Server:

var user = gs.getUser();
        var roleCheck = user.hasRole("snc_internal");
        var userGr = user.getRecord();
        var x = gs.getProperty("glide.servlet.uri") + gs.action.getGlideURI();
				if (x.indexOf("supplier") >= 0) {
          // if (roleCheck && (userGr.getValue("u_user_type") == "Guest") && (!userGr.getValue("u_org_id"))) {
                var y = "https://supplierportal.asda.uk/supplier?id=kb_article_view&sysparm_article=KB0034151";
                data.returnUrl = y;
							//gs.addInfoMessage(roleCheck);
          //  }

        }

Client:

api.controller=function($scope, spUtil) {
  /* widget controller */
  var c = this;
	
	function get() {
		spUtil.update($scope);
	}
	if(c.data.returnUrl != ""){
		window.location.href = returnUrl;
	}
1 ACCEPTED SOLUTION

Sid_Takali
Kilo Patron

Hi @Rosy14 Try below code

Client Side:

api.controller = function($scope, spUtil) {
    var c = this;

    function get() {
        spUtil.update($scope);
    }
    
    if (c.data.returnUrl) {  // Check if returnUrl is not empty or undefined
        window.location.href = c.data.returnUrl;  // Use c.data.returnUrl
    }
};

 

Server Side:

(function() {
    var user = gs.getUser();
    var roleCheck = user.hasRole("snc_internal");
    var userGr = user.getRecord();
    var x = gs.getProperty("glide.servlet.uri") + gs.action.getGlideURI();
    if (x.indexOf("supplier") >= 0) {
        var y = "https://supplierportal.asda.uk/supplier?id=kb_article_view&sysparm_article=KB0034151";
        data.returnUrl = y;
    } else {
        data.returnUrl = "";  
    }
})();

 

 

View solution in original post

1 REPLY 1

Sid_Takali
Kilo Patron

Hi @Rosy14 Try below code

Client Side:

api.controller = function($scope, spUtil) {
    var c = this;

    function get() {
        spUtil.update($scope);
    }
    
    if (c.data.returnUrl) {  // Check if returnUrl is not empty or undefined
        window.location.href = c.data.returnUrl;  // Use c.data.returnUrl
    }
};

 

Server Side:

(function() {
    var user = gs.getUser();
    var roleCheck = user.hasRole("snc_internal");
    var userGr = user.getRecord();
    var x = gs.getProperty("glide.servlet.uri") + gs.action.getGlideURI();
    if (x.indexOf("supplier") >= 0) {
        var y = "https://supplierportal.asda.uk/supplier?id=kb_article_view&sysparm_article=KB0034151";
        data.returnUrl = y;
    } else {
        data.returnUrl = "";  
    }
})();