Variable sys_id in widget server side script

ohhgr
Kilo Sage
Kilo Sage

Hello All,

I was stuck on this particular point and hope someone can point me in right direction.

I want to create a reusable widget (say a modified date picker), I would use it as a variable in multiple catalog items. Now, I'd like some options to dynamically change based on some options specified at the variable definition. (I could store them in a different table in future, but for simplicity assume that one additional field stores this information on 'item_option_new' table. My question is how can I identify which variable is being called in widget's server script?

In client controller I can get this information by using $scope.page.field.sys_id. But, I'd like to have this information at the server side so that I could provide the options from server side.

-Mandar

1 ACCEPTED SOLUTION

xiaix
Tera Guru

I completely understand what you're trying to do... or so I think.  I'm in the same boat.

 

I have a catalog item on the Service Portal to where I added a macro variable that loads a widget:

find_real_file.png

 

Now, when this widget loads, I want to grab the sys_id of the calling catalog item because in the Server Script, I want to query the item_option_new table to get the sys_id's of all the variables:

 

find_real_file.png

 

 

When the widget initially loads, it runs the Server Script and that's where I can't seem to get the sys_id of the calling catalog item... the same issue you're having.

 

The only way that I've found do what you're trying to do is by doing this:

 

find_real_file.png

find_real_file.png

find_real_file.png

 

However, this is not the way I want to go about it.  I need to grab that sys_id before any of the HTML Template code gets rendered.

 

I forked this into my own question in the Developer Community here (my Developer Community post)

View solution in original post

18 REPLIES 18

BALAJI40
Mega Sage

I did not understand fully, i have one point to say like same variable want to use in multiple catalog items


go with variable set and create variable in that.


Hey Balaji,



I'm using Service Portal. And the calendar picker would be a widget. So that I can use the widget option in variables default value to use it. So, the question above is referring to the server side /client controller part from Service Portal widget.



I hope that makes the question clearer now.



-Mandar


ohhgr
Kilo Sage
Kilo Sage

I guess, I've complicated the question.



All I want to know is, if there's a way we can fetch the variable sys_id value at the server side? Same value that we get at client side using page.field.sys_id?



-Mandar


Hi Mandar,



I believe you must be using in your server side code in your GlideRecord etc.   I have an alternative for this. You can use the GlideRecord in client controller itself with callback function. It will also work on client side. I am not sure whether this is the best way to achieve this or not but this will help you to accomplish your task.



Hope this helps.



Regards


Ujjawal