Reuse Client Script with Service Portal

jleon
Giga Contributor

Hello

I was watching the discussion

Reusing Client Scripts

Now I want to reuse client scripts for catalog items that will work under Service Portal. But we have the issue that the functions declared at the onLoad client scripts, are not recognized by the other client scripts, the functions seems to be mising when are called by other client scripts,

we have the function getNumberOfNights at the OnLoad Client Script BDA Recalc Totals-OnLoad, the mentioned function is being called at a onChange Client Script BDA recalc-Check-in

I am getting this error at the browser(Chrome) debug console

Despite I am using Varset as proposed at the mentioned discussion, I am still getting the error below (when is running under Service Portal)

js_includes_sp.jsx?v=03-22-2017_2340&lp=Wed_Jul_05_10_02_00_PDT_2017&c=12_202:64225 (g_env) [SCRIPT:EXEC] Error while running Client Script "BDA recalc-Check-in": ReferenceError: getNumberOfNights is not defined

How can we work with shared Client Script functions, when we are under Service Portal?

Adding Jim Coyne to the loop

jim.coyne

Thanks!

Jesús

7 REPLIES 7

Jim Coyne
Kilo Patron

I have not done any work with the Service Portal to be honest, but one quick thing to check is the UI Type field on the script record:


find_real_file.png



The value is set to "Desktop" by default but must be set to one of the other two in order for the script to run in the Portal.


jleon
Giga Contributor

Hi Jim



I am working with the Helsinki version. In my case I don't have the "Portal" option.   I have tried with the option 'Both',   with no luck.



which version are you using Jim?



find_real_file.png


Thanks!


Jesús


rrshah83
Tera Contributor

Is your problem addressed? I have a similar issue. It is terrible from a maintenance perspective to write the same functions in all client scripts. There has to be a way to write re-usable code for Service Portal...


jleon
Giga Contributor

Ritesh


I didn't find a solution for this, the work around that I applied was to replicate the functions at the client scripts. And part of the logic I was stored as ajax script includes to be called in each client script.



The advantage of this work around is that the logic at the Ajax side is not replicated at the client scripts.


Regards


Jesus