The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Populating Service Portal Record Producer with values via URL Schema

Allen Andreas
Tera Patron
Tera Patron

Hi everyone,

So I've googled for quite some time to try and see how to go about doing this, but I'm struggling. This isn't your ordinary navigate by URL schema, please take note that it's for the Service Portal, specifically. And by that, I have an icon-link, I would like to have that point to the create incident record producer (which is a catalog item and so I'm unable to follow this format: https://<instance name>/<sp url suffix>?id=<page id>&<page parameters>).

How can I set up a widget to navigate to the record producer (customer facing, not back-end form view) of the incident within the service portal AND fill in specific values for category, subcategory etc.?

I figured out the URL schema for the SP to open the back-end incident form and fill in values, but I need the customer facing version.

Anyone got any ideas?

Or how can I take: sp?id=sc_cat_item&sys_id=<sysid of record producer> and somehow pass values to that, unfortunately I don't think that's allowed. As I'd need to replace sys_id in that line to sys_id=-1 to be able to open a form to create, but again, it won't know which record producer or category item to open as we just took that sys_id out...


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
I invite you to visit my ServiceNow focused YouTube channel: Allenovation!
1 ACCEPTED SOLUTION

I found the mistake of my ways.  So it seems that $scope.page.g_form isnt available to all widgets.  I had to add a macro with a "widget" set to the new widget.

then it works.

So you'd have to add that variable on every form you want this to work on.

If you want to see it in action, hit me up on sndevs.slack.com @jace invite url: https://snowslack.herokuapp.com/

View solution in original post

16 REPLIES 16

Jace Benson
Mega Sage

So what I'm reading is you want to point to a record producer and set the variables by the URL.

Maybe I'm not reading that right.  In the past you could do that you could do that casue you could access `top`, `window`, `document`, or `jQuery`. 

So I think if you need this in the mean time you have to set up something to read url params consistenly,  That means a custom widget to set the fields/variables, or a dependency to do it. 
Either way you'll need to just access g_form from $scope.

You can do that by calling the following in the client script;

// source: https://sndevs.github.io/meetups/decks/sp-portal-custom-inputs/0.4.client.js.html
function($scope, $window) {
  // This is the controller, we've included
  // $scope in the function above because
  // it's easy to work with
  var c = this;
  // We are going to simplify accessing 
  // g_form within the client script by
  // setting it as a variable named g_form
  var g_form = $scope.page.g_form;
  //We are going to simplify accessing
  // g_form within the HTML by setting
  // it as a $scope attribute
  $scope.g_form = $scope.page.g_form;
  // from here you can just iterate over
  // the url params;
  //
  var params = new URLSearchParams($window.location.href.split('?')[1]);
  for (let p of params) {
    console.log('setting: ' + p[0] + ' => ' + p[1]);
    try {
      $scope.g_form.setValue(p[0],p[1]);
    } catch (error) {
      console.log('Error setting field', error);
    }
  }
}

Hi,

Thanks for that. So yea, basically I'm trying to ultimate get to the default catalog item > create incident.

Before that, I have different buttons to sort of walk the user through what the issue is (other people have used a select box on the form to have the user look at that and choose a category, then a relevant subcategory would pop up, etc.) however, we are using the SP sort of like a shopping cart experience. User would click Get Help? And then they would see all the "main" category choices as Icon Link widgets. Each widget links to another page that would then list their respective subcategories.

Now...once they get to their subcategory they want, they'd click that icon link, which would route them to the incident form with variables already filled in (the category and subcategory I just had them walk through). So I can manually go through and assign a certain URL or whatever to eat "icon link", but I wasn't sure how to get that done.

So for this suggestion you've provided. Where would I assign the client script? Which table? The incident table? (I imagine this is yes), and onLoad? Or am I assigning it to the widget, itself? but then what happens afterwards?


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
I invite you to visit my ServiceNow focused YouTube channel: Allenovation!

That script would be a client script on a widget or in a dependency, however that script should work in a widget, not sure if it would work in a dependency atm.  So you'd just have to add a widget to the oob sc_cat_item page.

Ok so I made a brand new widget, pasted that script in the client script section, added that widget to the OOB sc_cat_item page (and it disappeared, but that's expected since it's just a script). I then tried to do something like:

https://domain.service-now.com/sp?id=sc_cat_item&sys_id=<sys_id>&sysparm_query=category%3DHardware and it's not working. I also did query=category=Hardware as well, instead of sysparm_query.

Was there something else I should be doing?


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
I invite you to visit my ServiceNow focused YouTube channel: Allenovation!