In this webinar, our experts showcase a variety of demo use cases of how different components of the...
Many times we would like to include an HTML link in an email notification sent to user. Sometimes we could just use 'Regarding' field of email, but this only works if user uses Outlook Client and even then, email tagging may take a while and 'View Regarding' button is not available when user actually reads the email. In addition, we may want to have one entity as Regarding and another as additional link.
It does not sound very difficult, at least that is what I thought first time I encountered this requirement. I figured I could just use the GUID of the record to give user link in format of:
http://CRM/sfa/accts/edit.aspx?id={GUID}
As it turns out, the GUID is not available for workflows. With some searching, I found similar issues dating back to CRM 3.0 and some approaches that saved the GUID or the full link to a custom field if the Form is Update Form.
The obvious downside of this is that when a new record is created, it will not have value for the custom field unless the user opens up the form again after saving it. This was not enough for me, but it was the starting point for my solution:
Actual Solution
//ONSAVE //If we already have value in field, skip this logic if ((crmForm.all.po_workflowguid.DataValue == null ) ||(crmForm.all.po_workflowguid.DataValue=="")) { //Set temporary flag on the GUID field, based on which save was called. //This is important so we know which event to continue. if (event.Mode==2) crmForm.all.po_workflowguid.DataValue="SAVEANDCLOSE"; else if (event.Mode==59) crmForm.all.po_workflowguid.DataValue="SAVEANDNEW"; else crmForm.all.po_workflowguid.DataValue="SAVE";
//Force Form to save, in order to create GUID and re-load the form. crmForm.Save(); //Abort the original Save event.returnValue=false; return false; }
Add following logic to Onload Event.
//ONLOAD //Lets hide the field crmForm.all.po_workflowguid_c.style.display='none'; crmForm.all.po_workflowguid_d.style.display='none';
//Only process for Update Form if(crmForm.FormType == 2) { //If this is Update Form, we can simply set the GUID if ((crmForm.all.po_workflowguid.DataValue == null ) ||(crmForm.all.po_workflowguid.DataValue=="")) crmForm.all.po_workflowguid.DataValue=crmForm.ObjectId; else { //The Additional logic: Check for flag in GUID field //We will set the GUID and continue the type of save user initiated switch(crmForm.all.po_workflowguid.DataValue) { case "SAVEANDCLOSE": crmForm.all.po_workflowguid.DataValue=crmForm.ObjectId; crmForm.SaveAndClose(); break case "SAVE": crmForm.all.po_workflowguid.DataValue=crmForm.ObjectId; crmForm.Save(); break case "SAVEANDNEW": crmForm.all.po_workflowguid.DataValue=crmForm.ObjectId; crmForm.SubmitCrmForm(59, true, true, false); break default: break } } }
The downside of this approach is that when user saves the form for the first time, they will see a brief flicker from form loading twice.
Another way to achieve this functionality would be to write a custom Plugin for retrieving the GUID of entity and just using that in the workflow.
Hello. Why not simply adding the guid to the custom attribute in OnSave, along with forcing submit?
Hi Sander,
From the look of the code I'd say its because the GUID isn't known until the record is saved. So you need to save it, get the GUID, then save it again.
I'm using this code and it working nicely with one small tweak. I changed:
crmForm.all.po_workflowguid_c.style.display='none'
crmForm.all.po_workflowguid_d.style.display='none'
to:
crmForm.all.po_workflowguid_c.style.visibility='hidden'
crmForm.all.po_workflowguid_d.style.visibility='hidden'
Thanks for the post!
Cameron
Hi Cameron,
How can I default/set "cc" field to the user's account (email address) using email activity form based on the "onLoad" event?
Once the form is loaded, and cc field is defaulted to user's account, script must not restrict the user from adding multiple recipients as "cc" on this email form.
Awaiting your reply.
Mukesh
I have tried this technique using a plugin to set the value. I am having a problem in the format of the email generated by the workflow. CRM puts the value from the Guid variable into an HTML Span, thus making it unrecognizeable as a link.
Has anyone seen this problem?
I was having the same problem with CRM4 breaking my links when I tried to add the GUID field with the workflow. One work around that has worked for me is to create a custom field the contained the entire address with the GUID concatenated into the correct place using javascript. Then in the workflow just add the field by itself.
So something like this snippet on a load:
if(crmForm.all.new_url.DataValue == null)
{
crmForm.all.new_url.DataValue = 'http://servername:5555/leads/edit.aspx?id='
+ crmForm.ObjectId;
}