{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":301,"path":"api-reference/cllent-mobile-api-reference/m_formClientAPI.md","title":"m\\_form - Client","bundle":null,"doc_type":null,"release":"australia","body":"\n# m\\_form- Client\n\nProvides methods to get and set input values on input form screens, as well as display messages.\n\nThis API supports the following input types:\n\n-   Boolean\n-   Choice\n-   Date/time\n-   Number\n-   Reference\n-   String\n\nThis API can be used with the [MobileScriptIncludeCaller - Client](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/MobileScriptInclCallerClientAPI.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\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## m\\_form - addErrorMessage\\(String message\\)\n\nDisplays an error message at the top of the input form screen.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|The message to display.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nIn this example, an informational or error message is displayed on the form depending on the value entered for the priority.\n\n```\n// Client script in a Mobile UI Rule Action\nfunction onChange(inputName, newValue) { \n   var priority = newValue; \n   if (priority > 0 && priority < 3) { \n      getMessage(\"This incident should be handled ASAP\", function(response){ \n         m_form.addInfoMessage(response); \n      }); \n   } else { \n      getMessage(\"The selected priority is invalid\", function(response){ \n         m_form.addErrorMessage(response); \n      }); \n   }\t \n}\n```\n\n## m\\_form - addInfoMessage\\(String message\\)\n\nDisplays an informational message at the top of the input form screen.\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|The message to display.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nIn this example, an informational or error message is displayed on the form depending on the value entered for the priority.\n\n```\n// Client script in a Mobile UI Rule Action\nfunction onChange(inputName, newValue) { \n   var priority = newValue; \n   if (priority > 0 && priority < 3) { \n      getMessage(\"This incident should be handled ASAP\", function(response){ \n         m_form.addInfoMessage(response); \n      }); \n   } else { \n      getMessage(\"The selected priority is invalid\", function(response){ \n         m_form.addErrorMessage(response); \n      }); \n   }\t \n}\n```\n\n## m\\_form - getValue\\(String inputName\\)\n\nReturns the value of a specified input on an input form screen.\n\n|Name|Type|Description|\n|----|----|-----------|\n|inputName|String|Name of the input to return the value of.|\n\n<table id=\"table_mpp_tr2_mbc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nThe value of the specified input.**Note:** If the input is a choice list with multi-select, the return type is an array of strings containing the selected values.\n\n</td></tr></tbody>\n</table>This 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## m\\_form - setAffectedInputs\\(Array inputNames\\)\n\nAdds a shimmering effect to specified inputs indicating that the value is being set by a script.\n\nThe shimmering effect ends once the value for the input is set.\n\n|Name|Type|Description|\n|----|----|-----------|\n|inputNames|Array|Array of strings containing the names of inputs to apply the shimmer effect to.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis client script adds a shimmer effect to the caller input to indicate that it's auto-filled.\n\n```\n// Client script in a Mobile UI Rule Action\nfunction onChange(inputName, newValue) { \n   var affectedInputs = []; \n   affectedInputs.push(\"Caller\"); \n   m_form.setAffectedInputs(affectedInputs); \n   m_form.setValue(\"Caller\", [\"800b174138d089c868d09de320f9833b\", \"46d44a23a9fe19810012d100cca80666\"]); \n   var result = m_form.getValue(\"Caller\"); \n   console.log(`Ref test: ${result[0]}`); \n}\n```\n\n## m\\_form - setValue\\(String inputName, Object value, String displayValue\\)\n\nSets the value of a specified input on an input form screen.\n\n<table id=\"table_tp1_wr2_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\ninputName\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the input to set the value of.\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nObject\n\n</td><td>\n\nValue to set the input to.The data type of the value varies based on the input being set.\n\n</td></tr><tr><td>\n\ndisplayValue\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Use this parameter when setting the value of Reference type inputs.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example sets an integer value for the order input.\n\n```\nm_form.setValue(\"order\", 5);\n```\n\nThis example sets a string value for the description input.\n\n```\nm_form.setValue(\"description\", \"This is the description content\");\n```\n\nThis example uses an object containing the value and display value to set a reference type input.\n\n```\nm_form.setValue(\"Caller\", [{\"value\":\"800b174138d089c868d09de320f9833b\", \"displayValue\":\"Abel Tuter\"}]);\n```\n\n"}}