Follow

Shared Object

The Shared Object is a JavaScript variable that stores information on the window of the source app. You can read from it and write to it from any script you add to the Zapp, allowing you to create automations that enhance user experience. The following provides some examples of common use cases.

 

 

String Manipulation

 

You can leverage the Shared Object to manipulate strings on different pages in order to pre-populate fields on behalf of the user. For example, consider a Zapp where the username the user enters upon login makes up part of the text that should be entered into a field on the next page. To streamline the user experience, you can store the username in the shared object, add any necessary changes, and prepopulate the field.

 

First, open the Web Properties dialog by hovering over the username field in the mobile preview, and clicking the wrench icon.

 

Username_Wrench_Icon.png

 

Navigate to the "Properties" tab, and scroll down to the Overrides Actions section. Toggle on the "Click" override action, and enter your code (example below).

 

Click_Override.png

 

var loggedInUser = element.textContent;   // Create local object reference to page
var userName = loggedInUser.split("@")[0];    /*Extract pieces via methods such as 
split, slice, substring, regex, etc. as needed*/
shared.firstName = userName;    /* Create new shared object variable to reference 
in Zapp*/
element.textContent = userName + "@mycompany.com" /* Modify string (if needed) and set 
on page to re-use on future pages via Automation feature*/

 

You can then pre-populate fields on the subsequent pages by creating an Automation. Please refer to this article for more information.

 

Alternatively, you can also leverage the Shared Object in an Override to pre-populate the field. For example, enter the below code in the "Set Text Field Value" override action.

 

Set_Text_Field_Value.png

 

element.value = shared.currentUser;

 

 

URL Query String

 

You can also leverage the Shared Object to add URL Query String Parameters. For example, consider a Zapp where, following login, you would like to display a list of accounts or contacts the user owns. Rather than loading a blank search page, having the user enter his information, and then searching, parameters can be passed to the URL to automate the process. Enter code like the sample below in the "Open Lookup" override action.

 

Screen_Shot_2017-06-16_at_2.46.11_PM.png

 

var searchUrl = "https://manage.prod.capriza.com/master_apps?utf8=✓&q=" + shared.firstName
+ "%40mycompany.com&exclude_capriza_users=false&order_by=Version+Date&action=";
/*Using firstName from the previous example,
build URL from static items plus query
parameters*/
window.location.href = searchUrl; /* Set window location on the button click Override
action*/
resolve(); // Async promise return

 

For more information on Capriza JavaScript Objects, please refer to this article.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.