Set the Mobile phone through script (Phone Number (E164))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 10:28 AM
Hi All,
For a user in the sys_user table, I have the field mobile_phone, of type Phone Number (E164).
I am working in the background script to update the value of the number to any number. eg. 91 5658874526. This should ideally work as I am getting a row count 1 for update after script execution.
However, the phone number in the user records is empty and when I log the value again, it is empty as well. How can I set the value of the mobile of a user through script?
Is there anything I am skipping?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2024 04:43 AM - edited 08-03-2024 04:57 AM
Hi @TanayaGavande ,
I would recommend not to use current as variable name. Instead use meaningful variable name.
Please try the below in background script:
var updateNumber = new GlideRecord('sys_user');
if (updateNumber.get('99c1375083670610e1c15d10feaad3b1')) {
updateNumber.setValue('mobile_phone', '+916723854563');
updateNumber.update();
}
Result:
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2024 04:55 AM
You need to pass the correct country code in order to update it. Passing incorrect code will not update it.
More example:
var updateNumber = new GlideRecord('sys_user');
if (updateNumber.get('99c1375083670610e1c15d10feaad3b1')) {
updateNumber.setValue('mobile_phone', '+33109858351');
updateNumber.update();
}
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 06:34 AM
Hi @SN_Learn ,
Thank you for your reply.
When I try to update it as you suggested, with the extension of, say +44 (UK), the country gets updated correctly but the number is different.
What you said worked perfect in my PDI, but not in the client instance. Here are the screenshots of the client instance:
Also, keeping the mobile number same, can I change the country/territory of every user to a specific one? Like North America, or UK?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 10:09 AM
Hi @TanayaGavande ,
We need to provide the correct country code + phone number, if not provided then it will not update.
Also, in your client environment please check whether the field is of same type(Phone Number (E164))?
I tried in PDI for the UK and North America:
//UK
var updateNumber = new GlideRecord('sys_user');
if (updateNumber.get('62526fa1d701120035ae23c7ce6103c6')) {
updateNumber.setValue('mobile_phone', '+441312345679');
updateNumber.update();
}
var updateNumber = new GlideRecord('sys_user');
if (updateNumber.get('62526fa1d701120035ae23c7ce6103c6')) {
updateNumber.setValue('mobile_phone', '+14131234567');
updateNumber.update();
}
Mark this as Helpful / Accept the Solution if this helps.