Hello Team,
I am brand new to javascript. So, I'm struggling to understand the correct syntax for my requirement. I have a main email form and for that specific form, I'd like to populate the From column with a queue mailbox when the form state (getformtype) value is Create (1).
Here is the code from the .js web resource I've created:
function _setFromUser() { var formType = formContext.ui.getFormType(); var legalQueueID = "dcc80a43-39e4-e711-817f-e0071b715bc1"; var recordName = ""; var entityName = "queue"; if(formType == 1) { Xrm.Page.getControl("from").getAttribute().setValue([{ id: legalQueueID, name: recordName, entityType: entityName }]); }}
Here is how I have the event handler configured on the form:
Here is the error I receive:
ReferenceError: formContext is not defined at eval (eval at _executeFunctionInternal (https://********.crm.dynamics.com/uclient/scripts/app.js?v=1.4.3618-2111.2:1988:5296), :1:2) at eval () at y._executeFunctionInternal (https://********.crm.dynamics.com/uclient/scripts/app.js?v=1.4.3618-2111.2:1988:5296) at y.executeSync_DO_NOT_USE (https://********.crm.dynamics.com/uclient/scripts/app.js?v=1.4.3618-2111.2:1988:3404) at r (https://********.crm.dynamics.com/uclient/scripts/app.js?v=1.4.3618-2111.2:1719:61) at ee._convertEventDescriptorToCustomEvent (https://********.crm.dynamics.com/uclient/scripts/app.js?v=1.4.3618-2111.2:151:32656) at https://********.crm.dynamics.com/uclient/scripts/app.js?v=1.4.3618-2111.2:151:32306 at Array.map () at ee._getEventHandlerList (https://********.crm.dynamics.com/uclient/scripts/app.js?v=1.4.3618-2111.2:151:32294) at Object.execute (https://********.crm.dynamics.com/uclient/scripts/app.js?v=1.4.3618-2111.2:151:20784)
I've tried passing the formContext parameter to the function using the "Comma separated list of parameters that will be passed to the function" column in the event handler dialog. But, that doesn't seem to work either. Any ideas?
Thanks so much. This worked perfectly. The only change I had to make was adding an additional return value to the if(formType) statement. I added an OR operator to include the "undefined" form state because it seems as though the client API does not recognize draft replies as a "create" form state. So, code on line 7 now looks like this:
if(formType == 1 || formType ==0)
And now it appears to be working perfectly for my requirement. Thanks again!
Hi,
You need to update your code as below -
function _setFromUser(executionContext) { var formContext=executionContext.getFormContext(); var formType = formContext.ui.getFormType(); var legalQueueID = "dcc80a43-39e4-e711-817f-e0071b715bc1"; var recordName = ""; var entityName = "queue"; if(formType == 1) { Xrm.Page.getControl("from").getAttribute().setValue([{ id: legalQueueID, name: recordName, entityType: entityName }]); }}
Please mark my answer verified if this is helpful!
Regards,
Bipin Kumar
Follow my Blog: xrmdynamicscrm.wordpress.com/
Hi,
The new formContext object is used to in place of the Xrm.Page object.
It should be used in its normal form as follows:
function displayName(executionContext) { var formContext = executionContext.getFormContext(); // get formContext // use formContext instead of Xrm.Page ... }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,900 Super User 2024 Season 2
Martin Dráb 229,297 Most Valuable Professional
nmaenpaa 101,156