$location.search( ) with ng-click to redirect to the same page without loading

Elton2
Tera Contributor

Hi everyone,

When clicking on the table row, the user will be directed to a form, 

but this form must be on the same page without having to load it. 

 

Obs.: Before the user was clicking on the record and being directed to another page, 

due to this I am using the “sys_id” of the page.

 

I have to use "$location.search", but its not working:

 

<!--HTML-->
<li>
<td  ng-repeat="record in allRecords"  ng-if="options.redirect == 'true'" class="pointer list__short" ng-switch="data.column_types[field.field]">
<span class="record_list" ng-click="$location.search({data.url + sys_id})"></span>
</td>
</li>
 
/*Client Script*/
    /* Redirect */
    $scope.redirect = function (record) {
        if (c.options.redirect == 'false')
            return;

        if (!record) return;
        var url = c.data.url + record.sys_id;
        $window.open(url, c.options.target);
    }
 
 
/*Server Script*/
data.url = $sp.getPortalRecord().getDisplayValue('url_suffix') + '?id=' + page + '&table=' + data.table + '&sys_id=';
 
Could anybody support me?!
Tks
2 ACCEPTED SOLUTIONS

jaheerhattiwale
Mega Sage
Mega Sage

@Elton2 Tried and Tested solution.

 

Please try below code:

Server:

data.table = "<TABLE NAME HERE>";
data.view = "<VIEW NAME HERE";
 
HTML:
<li>
<td  ng-repeat="record in allRecords"  ng-if="options.redirect == 'true'" class="pointer list__short" ng-switch="data.column_types[field.field]">
<span class="record_list" ng-click="c.goToRecord(record.sys_id)"></span>
</td>
</li>
 
Client controller:
c.goToRecord = function(recordId){
    var parms = {
        id: 'form',
        table: c.data.table,
        view: c.data.view,
        sys_id: recordId
    };

    $location.search(parms);
};
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

@Elton2 We can open in same tab also as follows

 

$window.open(url, c.options.target);

 

Change the above line to 

 

$window.open(url, "_self);

OR

In the instance options you should have a target field there, select _self there.

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

7 REPLIES 7

@Elton2 We can open in same tab also as follows

 

$window.open(url, c.options.target);

 

Change the above line to 

 

$window.open(url, "_self);

OR

In the instance options you should have a target field there, select _self there.

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Elton2
Tera Contributor

Hi @jaheerhattiwale , how are you?!

It's working!!!

Thanks for your support 😉

@Elton2 Welcome😊

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023