Error in server script in scoped widget

arnabwa
Giga Guru

Hi Snow enthusiasts,

I'm facing an issue while cloning a global widget into a scoped environment. When I preview the widget this is the error :

error1.PNG

What I am actually doing is copying the global workers portal to a completely scoped environment. I have made the necessary changes in script though may be not all since I'm very new service portal (actually starting from zero).

here is the server script where the error line is present :

server script.PNG

Could anyone please direct me how to correct this and most importantly what is this error all about so that I can learn why is it so?

Also I would request if anyone has done this implementation for their client. The requirement is :

"Moving the Global Workers Portal to a Private scope for generating time cards" OR we can simply put this way :

"Make the Global Workers Portal work in a private scope exactly the way it is now in global scope"

Many Thanks,

Arnab

7 REPLIES 7

Hi Chuck,



Another finding that I wanted to share :


Since I have cloned the OOB widget for Workers portal (Time Card Grid) in our scoped environment, so I checked putting log statements as to what is the output in the OOB widget in the global scope for the line var timesheetId = $sp.getParameter('sysparm_timesheet_id') || input.timesheetId;



var timesheetId = $sp.getParameter('sysparm_timesheet_id') || input.timesheetId;


gs.info("timesheetid## : " + input.timesheetId); // This gives me undefined value


gs.info("$sp.getParameter : " +$sp.getParameter('sysparm_timesheet_id')); //This gives me NULL value



after this we have the following code :


if(!timesheetId)//Due to this it gets inside the if statement


timesheetId = new TimeSheetFactory().getTimeSheet(data.userId);


data.timesheetId = timesheetId;


var timesheet = new GlideRecord('time_sheet');


timesheet.get(timesheetId);


var timecardGr = new GlideRecord('time_card');


timecardGr.newRecord();


data.canCreateTimecards = timecardGr.canCreate();



But my question is if in the OOB widget both gs.info("timesheetid## : " + input.timesheetId); AND gs.info("$sp.getParameter : " +$sp.getParameter('sysparm_timesheet_id')); gives no values and then accordingly goes on further with script then Why does it give me an error when I copy the code in scoped environment? Why am I not proceeding to the next line of codes after getting the values undefined too?


I mean where am I supposed to define the value of timesheetId?



Thanks,


Arnab


Hi @arnabwa 

Were you able to solve this issue pls?

Why does it work in Global and in the custom scope?

Hi Vijaya,

 

This was a real pain my head that time back in 2017. By replying to this post, you kind of made me nostalgic. Thanks though. That was the first time I was dealing with service portal. This task was the most complex one that I had met as per my snow experience even until now. So, this question is very close to my heart. 

 

Yes I was able to achieve this. Basically this particular issue was that the 'timesheetId' field was not being set properly. Means it was not getting any value and hence undefined and undefined gives this error. 

In line 4, the 'sysparm_timesheet_id' and 'input.timesheetId', both did not have value.

'sysparm_timesheet_id' was null because the page URL did not have this parameter.

'input.timesheetId' was undefined because during first load of any widget, input objects are undefined. This is how snow portal works. That time I had thought this was an error but its not. Its the expected behaviour that input object is undefined on widget load.

 

By the way, what are you searching for?

 

Thanks,

Arnab