{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":213,"path":"api-reference/cllent-mobile-api-reference/MobileScriptInclCallerClientAPI.md","title":"MobileScriptIncludeCaller - Client","bundle":null,"doc_type":null,"release":"australia","body":"\n# MobileScriptIncludeCaller- Client\n\nProvides methods to call script includes from Mobile UI Rule Actions.\n\nThis API can be used with the [m\\_form - Client](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/m_formClientAPI.md) API to auto-fill inputs on input form screens. For more information about input form screens, see [Input form screen](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/mobile/parameter-input-screen.md).\n\nUse this API in the **Client script** field of a Mobile UI Rule Action. For instructions on configuring a Mobile UI Rule Action with the correct settings for this API, see [Configure auto-fill inputs on input form screens](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/mobile/config-autofil-inputs-nptfrmscrn.md).\n\nThe script include must have the **Mobile callable** field selected to be called by this API.\n\n**Parent Topic:**[Client mobile API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/api-client-mobile.md)\n\n## MobileScriptIncludeCaller - MobileScriptIncludeCaller\\(String scriptName, String functionName\\)\n\nCreates an instance of the MobileScriptIncludeCaller class with the script include and function to call.\n\n<table id=\"table_umw_wlk_mbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nscriptName\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the mobile-callable script include to call.If the script include supports cross-scope access and it's in a different scope than the client script, the name of the script include must be prefixed with the scope.\n\n</td></tr><tr><td>\n\nfunctionName\n\n</td><td>\n\nString\n\n</td><td>\n\nThe public function to call in the script include.\n\n</td></tr></tbody>\n</table>This example shows how to create an instance of the MobileScriptIncludeCaller class that can be used to call the `getBusinessTitle()` function in the UserUtilsTest script include.\n\n```\nvar caller = new MobileScriptIncludeCaller(\"UserUtilsTest\", \"getBusinessTitle\");\n```\n\n## MobileScriptIncludeCaller - addParam\\(String key, Object value\\)\n\nAdds a parameter to pass when calling the script include.\n\nThis method enables you to pass values from the input form to the script include.\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|Key to use for the parameter.|\n|value|Object|Value of the parameter.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to add the value of the employee\\_id input from the input form to the MobileScriptIncludeCaller object.\n\n```\nvar employeeId = m_form.getValue(\"employee_id\"); \nvar caller = new MobileScriptIncludeCaller(\"UserUtilsTest\", \"getBusinessTitle\"); \ncaller.addParam(\"employeeId\", employeeId);\n```\n\n## MobileScriptIncludeCaller - call\\(Function successCallback, Function errorCallback\\)\n\nCalls the script include specified by the constructor.\n\nThe server call executes asynchronously and the script include's response is passed to the callback function. If the response from the server fails, for example if the script include isn’t found, the response argument passed to the callback is empty or null.\n\nThe script include must have the **Mobile callable** field selected to be called by this method.\n\n<table id=\"table_es1_b5l_mbc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nsuccessCallback\n\n</td><td>\n\nFunction\n\n</td><td>\n\nOptional. The name of the callback function to process the results returned by the server.If a callback function isn’t provided, this method returns a promise, which can be consumed using the [Promise API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).\n\n</td></tr><tr><td>\n\nerrorCallback\n\n</td><td>\n\nFunction\n\n</td><td>\n\nOptional. The name of the callback function to call if an error occurs.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis client script passes the employee\\_id input value to the script include, which uses the ID to look up the employee's title. The title is provided to the callback function, which it uses to auto-fill the business\\_title input on the input form screen.\n\n```\n// Client script in a Mobile UI Rule Action\nfunction onChange(inputName, newValue) { \n   var employeeId = m_form.getValue(\"employee_id\"); \n   var caller = new MobileScriptIncludeCaller(\"UserUtilsTest\", \"getBusinessTitle\"); \n   caller.addParam(\"employeeId\", employeeId); \n   caller.call(function(response) { \n      m_form.setValue(\"business_title\", response); \n   }); \n}\n```\n\nScript include.\n\n```\n// Mobile callable script include\nvar UserUtilsTest = Class.create(); \nUserUtilsTest.prototype = Object.extendsObject(global.AbstractMobileCallableInclude, { \n   getBusinessTitle: function() { \n      var employeeId = this.getParameter(\"employeeId\"); \n      var gr = new GlideRecord(\"sys_user\"); \n      gr.get(employeeId); \n      return gr.getValue(\"title\"); \n   }, \n   type: 'UserUtilsTest' \n});\n```\n\n"}}