Skip to main content

Utility Methods

info

Utility methods which do not return any value work only on preview screen

UTILITY is a Javascript API provided by DronaHQ to perform various actions directly from your javascript code. It enables you to use actions which are present in actionflow builder directly from the code giving you more control on the behaviour of your application.

TOAST

UTILITY.TOAST() method can be used to show toast messages.

Usage
UTILITY.TOAST(type,title,message,position,closeButton,timeout);
Parameters
ParameterAcceptsPossible values
typestring'info', 'error', 'success', 'warning'
titlestringany string value
messagestringany string value
positionstring'toast-top-right','toast-top-left', 'toast-top-center', 'toast-bottom-right' , 'toast-bottom-left', 'toast-bottom-center', 'toast-top-full-width, 'toast-bottom-full-width'
closeButtonbooleantrue/false
timeoutNumberany positive numerical value (in milliseconds)
Example
UTILITY.TOAST('success','Toast says','Hello','toast-top-right',true,5000);

CONFIRM

UTILITY.CONFIRM() method can be used to show a prompt message to the user and get input such as ok and cancel. This method returns a Promise so the response needs to be captured using await keyword.

Usage
UTILITY.CONFIRM(title,message,confirmButtonText,cancelButtonText);
Parameters
ParameterAcceptsPossible values
titlestringany string value
messagestringany string value
confirmButtonTextstringany string value
cancelButtonTextstringany string value
Example
await UTILITY.CONFIRM('Confirm says','Confirm this message','OK','Cancel');
User Input

When the Promise resolves, the user input will be received in the action key inside a javascript object:

{
action: 'OK'
}

ALERT

UTILITY.ALERT() method can be used to show a alert message to the user. This method returns a Promise so the response needs to be captured using await keyword.

Usage
UTILITY.ALERT(type,title,message,confirmButtonText);
Parameters
ParameterAcceptsPossible values
typestring'info', 'error', 'success'
titlestringany string value
messagestringany string value
confirmButtonTextstringany string value
Example
await UTILITY.ALERT('success','Alert says','Hello','Ok');
User Input

When the Promise resolves, the user input will be received as a boolean value:

true

EMAIL

UTILITY.EMAIL() method can be used to send emails.

Usage
UTILITY.EMAIL(subject,body,recipients);
Parameters
ParameterAcceptsPossible values
subjectstringany string value
bodystringany string value
recipientsstringstring of email ids (Comma separated)
Example
UTILITY.EMAIL('This is subject','Hello','user1@mail.com,user2@mail.com');

CALL

UTILITY.CALL() method can be used to make calls.

Usage
UTILITY.CALL(phoneNumber);
Parameters
ParameterAcceptsPossible values
phoneNumberNumberany numerical value
Example
UTILITY.CALL(9699194532);

SMS

UTILITY.SMS() method can be used to send sms.

Usage
UTILITY.SMS(phoneNumbers,message);
Parameters
ParameterAcceptsPossible values
phoneNumbersstringstring of phone numbers (comma separated)
messagestringany string value
Example
UTILITY.SMS('9699194532,9619723541','Hello');

CALLRESTAPI

UTILITY.CALLRESTAPI() method can be used to communicate with api servers using various HTTP methods like GET, POST, PUT, PATCH, and DELETE. This method returns a promise and to get the response use await keyword.

Usage
UTILITY.CALLRESTAPI(url, method, headers, data, useProxy, timeout);
Parameters
ParameterAcceptsPossible values
urlstringendpoint url to send the request
methodstring'GET', 'POST', 'PUT', 'PATCH', 'DELETE'
headersobjectjson data to send in request headers
dataobjectjson data to send in request body
useProxybooleantrue/false to use proxy
timeoutnumberany numerical value in milliseconds
Example GET Request
await UTILITY.CALLRESTAPI('https://exampleapi.com/api/users/','GET');
info

headers, data, useProxy and timeout are optional parameters, in case you don't want to specify any of them, put an empty string ('') instead while calling the method.

Example POST Request
await UTILITY.CALLRESTAPI(
'https://exampleapi.com/api/users/',
'POST',
'',
{'name':'morpheus','job':'leader'}
);

SETCTRLVALUE

UTILITY.SETCTRLVALUE() method can be used to set the value of a control. The method takes an array of objects as input and each object has two keys called name and value. The name key takes control's unique name which can be found in the right side properties panel on the builder screen.

Usage
UTILITY.SETCTRLVALUE(
[
{name: 'controlUniqueName' , value: 'Yourvalue'},
{name: 'anothercontrolUniqueName' , value: 'Yourvalue'}
]
);
Object Parameters
ParameterAcceptsPossible values
namestringControl's unique name
valuestring or objectany string value for single value controls and object for composite controls
selected_valuestring or arrayany string value or array of strings for list type controls
Example for single value controls
UTILITY.SETCTRLVALUE(
[
{name:'textinput',value:'DronaHQ'}
]
);
Example for composite controls
UTILITY.SETCTRLVALUE(
[
{
name:'address',
value: {
address1: "test",
address2: "abc",
city: "mumbai",
country: "india",
state: "mh",
zip: "66666666666"
}
}
]
);
Example for list controls
let dd_data = [
{
"name": "test1",
"value": "test1"
},
{
"name": "test",
"value": "test"
}
]
UTILITY.SETCTRLVALUE([
{
name: "advanceddropdown",
value: dd_data,
selected_value: "test"
}
])

HIDECTRL

UTILITY.HIDECTRL() method can be used to trigger hide action on a visible control. The method takes an array of strings which contains unique names of the controls.

Usage
UTILITY.HIDECTRL(controlUniqueNameArray);
Parameters
ParameterAcceptsPossible values
controlUniqueNameArrayarrayarray of strings (control unique names)
Example
UTILITY.HIDECTRL(['textinput','textinput1']);

SHOWCTRL

UTILITY.SHOWCTRL() method can be used to trigger show action on a hidden control. The method takes an array of strings which contains unique names of the controls.

Usage
UTILITY.SHOWCTRL(controlUniqueNameArray);
Parameters
ParameterAcceptsPossible values
controlUniqueNameArrayarrayarray of strings (control unique names)
Example
UTILITY.SHOWCTRL(['textinput','textinput1']);

SETVARIABLE

UTILITY.SETVARIABLE() method can be used to overwrite the value returned by a Custom Javascript code. The method takes an array of objects as input and returns a promise. Each object has two keys called name and value. The name key takes variable name and value takes any string value which needs to be set.

Usage
 UTILITY.SETVARIABLE([{name: 'variableUniqueName' , value: 'Yourvalue'}]);
Parameters
ParameterAcceptsPossible values
namestringvariable name
valuestringany string value for single value controls and object for composite
Example
await UTILITY.SETVARIABLE([{name: 'js_script_1' , value: 'value1'},{name: 'js_script_2' , value: 'value2'}]);

UTILITY.NAVIGATE() method can be used to navigate from one screen to another screen.

Usage
UTILITY.NAVIGATE(screenId,transition,resetTargetPage,withValidation);
Parameters
ParameterAcceptsPossible values
screenIdstring'Screen Id' present in properties panel on the builder
transitionstring0 or 1 in string value
resetTargetPagebooleantrue/false
withValidationbooleantrue/false
Example
UTILITY.NAVIGATE('screen-2','1',false,false);

CONFETTI

UTILITY.CONFETTI() method can be used to trigger confetti action.

Usage
UTILITY.CONFETTI(spread,particleCount,originX,originY);
Parameters
ParameterAcceptsPossible values
spreadnumberany number to define confetti spread over the page
particleCountnumbernumber of particles in confetti
originXnumbervalue in the range 0-1 for position on x-axis
originYnumbervalue in the range 0-1 for position on y-axis
Example
UTILITY.CONFETTI(70,400,0.5,0.5);

SHOWCTRLLOADER

UTILITY.SHOWCTRLLOADER() method can be used to show a loader on a particular control.

Usage
UTILITY.SHOWCTRLLOADER(controlUniqueNameArray);
Parameters
ParameterAcceptsPossible values
controlUniqueNameArrayarrayarray of strings (control unique names)
Example
UTILITY.SHOWCTRLLOADER(['dashboard','dashboard1']);

HIDECTRLLOADER

UTILITY.HIDECTRLLOADER() method can be used to hide the loader which is running on particular control.

Usage
UTILITY.HIDECTRLLOADER(controlUniqueNameArray);
Parameters
ParameterAcceptsPossible values
controlUniqueNameArrayarrayarray of strings (control unique names)
Example
UTILITY.HIDECTRLLOADER(['dashboard','dashboard1']);

EXITAPP

UTILITY.EXITAPP() method can be used to trigger exit app action.

Usage
UTILITY.EXITAPP();

LOGOUT

UTILITY.LOGOUT() method can be used to trigger logout action.

Usage
UTILITY.LOGOUT();

REFRESHCTRLDATA

UTILITY.REFRESHCTRLDATA() method can be used to reset the value of a control. The method takes an array of strings as input which have unique names of the controls that need to be reset.

Usage
UTILITY.REFRESHCTRLDATA(ctrlUniqueNames, triggerDependentDataQuery, tableGridPagination);
Parameters
ParameterAcceptsPossible values
ctrlUniqueNamesarrayarray of strings (control unique names)
triggerDependentDataQuerybooleantrue/false
tableGridPaginationbooleantrue/false
Example
UTILITY.REFRESHCTRLDATA(['textinput','textinput1'],false,false);

INVOKEACTIONFLOW

UTILITY.INVOKEACTIONFLOW() method can be used to invoke an actionflow which set on any event of a control. The value for the event_name parameter is visible in the heading part of the actionflow builder screen.

Usage
UTILITY.INVOKEACTIONFLOW('controlUniqueName','event_name');
Parameters
ParameterAcceptsPossible values
controlUniqueNamestringcontrol's unique name in string format
event_namestringcontrol's event name in string format
Example
UTILITY.INVOKEACTIONFLOW('button','button_click');

COPYTOCLIPBOARD

UTILITY.COPYTOCLIPBOARD() method can be used to trigger the copy to clipboard action.

Usage
UTILITY.COPYTOCLIPBOARD(text); 
Parameters
ParameterAcceptsPossible values
textstringany string value
Example
UTILITY.COPYTOCLIPBOARD('DronaHQ'); 

OPENURL

UTILITY.OPENURL() method can be used to open a url in a new tab.

Usage
UTILITY.OPENURL(url);
Parameters
ParameterAcceptsPossible values
urlstringany string value
info

Please make sure that the url entered should always start with "https://"

Example
UTILITY.OPENURL('https://www.google.com/');

PLAYSOUND

UTILITY.PLAYSOUND() method can be used to play any mp3 file by passing url.

Usage
UTILITY.PLAYSOUND(url);
Parameters
ParameterAcceptsPossible values
urlstringany string value
Example
UTILITY.PLAYSOUND('https://dronamobilepublic.s3.amazonaws.com/DRONA5_Team19020/content/app/images/Qg7Zwtep6a.mp3');

UTILITY.NAVIGATETOAUTHSCREEN() method can be used to trigger the Navigate to Authentication Screen action.

Usage
UTILITY.NAVIGATETOAUTHSCREEN(maintainCredentials,resetLogin);
Parameters
ParameterAcceptsPossible values
maintainCredentialsbooleantrue/false
resetLoginbooleantrue/false
Example
UTILITY.NAVIGATETOAUTHSCREEN(false,false);

MICROAPPNAV

UTILITY.MICROAPPNAV() method can be used to trigger the MicroApp Navigation action. It is also possible to pass key value pairs to the app we wish to navigate to in the form of an array of objects. The appId can be obtained from the actionflow builder in Microapp nav action.

Usage
UTILITY.MICROAPPNAV('appId',[{queryKey: 'yourkey', queryValue: 'yourvalue'}]);
Parameters
ParameterAcceptsPossible values
appIdstringnumerical appId in string form
keyValueArrayarrayarray of objects containing key value pairs
Example
UTILITY.MICROAPPNAV('4139',[{queryKey: 'key1', queryValue: 'value1'}]);

SETLOCALSTORAGE

UTILITY.SETLOCALSTORAGE() method can be used to store key value pairs locally. This method returns a Promise, so make sure to use the await keyword to successfully complete the operation.

Usage
UTILITY.SETLOCALSTORAGE(key, value);
Parameters
ParameterAcceptsPossible values
keystringany string value
valuestringany string value
Example
UTILITY.SETLOCALSTORAGE('dronahq', {Name:John,Age:25})

GETLOCALSTORAGE

UTILITY.GETLOCALSTORAGE() method can be used to retrieved the locally stored value using its unique key. This method returns a Promise, so make sure to use the await keyword to successfully complete the operation.

Usage
UTILITY.GETLOCALSTORAGE(key);
Parameters
ParameterAcceptsPossible values
keystringany string value
Example
UTILITY.GETLOCALSTORAGE('dronahq');

CLEARLOCALSTORAGE

UTILITY.CLEARLOCALSTORAGE() method can be used to remove the locally stored key value pairs. This method returns a Promise, so make sure to use the await keyword to successfully complete the operation.

Usage
UTILITY.CLEARLOCALSTORAGE(key)
Parameters
ParameterAcceptsPossible values
keystringany string value
Example
UTILITY.CLEARLOCALSTORAGE(key)