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.

Record Watcher not working

Vivek Prakash
Tera Contributor

I am tying to retrieve the status of a field from a table for a new record using record watcher but it won't work. I have added spUtil at header and added an alert statement at watcher function but nothing is being logged.

Any idea's why?

 

The code

spUtil.recordWatch($scope, "tableName", "sys_id" +c.orderId, function(response) {
        
    // Returns the data inserted or updated on the table 
    alert("orderId 1 " +c.orderId);
    c.data.action = 'orderUpdationCheck';
    c.data.orderId = c.orderId;   
    c.server.update().then(function(response){
    c.data.action = '';
    if(response.ordered)
        $window.location.href = c.data.portalLandingURL;
    });
        

});

2 REPLIES 2

-O-
Kilo Patron

The filter is not OK; it should be:

"sys_id=" + c.orderId

notice the extra =.

Mohith Devatte
Tera Sage
Tera Sage

Hello @Vivek Prakash ,

if you are getting your order id from server you need to write it as 

spUtil.recordWatch($scope, "tableName", "sys_id="+c.data.orderId, function(response) {
        
    // Returns the data inserted or updated on the table 
    alert("orderId 1 " +c.orderId);
    c.data.action = 'orderUpdationCheck';
    c.data.orderId = c.orderId;   
    c.server.update().then(function(response){
    c.data.action = '';
    if(response.ordered)
        $window.location.href = c.data.portalLandingURL;
    });
        

});

if it is client side variable where you stored you order id it should be like below 

spUtil.recordWatch($scope, "tableName", "sys_id="+c.orderId, function(response) {
        
    // Returns the data inserted or updated on the table 
    alert("orderId 1 " +c.orderId);
    c.data.action = 'orderUpdationCheck';
    c.data.orderId = c.orderId;   
    c.server.update().then(function(response){
    c.data.action = '';
    if(response.ordered)
        $window.location.href = c.data.portalLandingURL;
    });
        

});

PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU