get Sys_ID from Service portal URL

yogeshpoyyara
Mega Expert

I am trying to get the Sys_Id from the URL and then fetch the related records from a table.

I tried, data.sys_id = $sp.getParameter("sys_id"); in the server script ; but it doesn't fetch the sys_id from the URL.

Please assist.

Regards,

Yogesh PH

1 ACCEPTED SOLUTION

Yogesh,



You want to use addQuery, as opposed to addEncodedQuery when looking up just the sys_id.



If you log ' $sp.getParameter("sys_id");', what does it return?




Thanks.


View solution in original post

10 REPLIES 10

Paul Wydra III
Tera Expert

Hi Yogesh,



Could you please provide some more info so that I can assist? At first glance, that appears to be the correct use to get the sys_id from the URL.



  • What does your URL look like?
  • Where are you trying to use the sys_id? Client, Server or HTML?
    • Please post the script for where you are retrieving the sys_id
  • What is data.sys_id returning?
    • Did you try to enable logging of the data object and check the console to see if it's populated? (CTRL-Right click widget and choose "Log to console: $scope.data")


Thanks.


Hi paulw(acorio),



Below is the Server Query:



(function () {


data.tasks = [];


  //data.sys_id = $sp.getParameter("sys_id");


  var gr = new GlideRecord('u_u_task');


  gr.addEncodedQuery('sys_id', $sp.getParameter("sys_id") );


  gr.query();


  while (gr.next()){


  var task =   {};



  task.name = gr.getDisplayValue('u_uname');


  task.details = gr.getDisplayValue('u_details');


  data.tasks.push(task);


  }




})();



This actually return the entire table content irrespective of the URL: /?sys_id=18e8634ddb6d62006430f7fdbf961976&view=sp&id=yogi_test5&table=u_u_task



Please share information of checking the log console.




Regards,


Yogesh PH


Yogesh,



You want to use addQuery, as opposed to addEncodedQuery when looking up just the sys_id.



If you log ' $sp.getParameter("sys_id");', what does it return?




Thanks.


Hi Paul,



Now how do i delete a record?



I put the below script in client script; but delete function doesn't work.



function deleteAlertRecords(){


var rec = new GlideRecord('u_u_task');



rec.addQuery('data.sys_id');


rec.query();


while(rec.next()){


spUtil.addErrorMessage("This record is deleted");


rec.deleteRecord();


}


}



Regards,


Yogesh PH