web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Make field Required on Completion of Phone Call

(0) ShareShare
ReportReport
Posted on by 895

I have an issue where I have a field "Follow Up Type" which is used in a Workflow to create a follow up Appintment or Phone Call, at the moment I have this set to a required field however I want it to only be required when the call is completed.

i.e. User can open the call and close without populating (When checking ahead in their work etc...) but when they complete the call they must select the Follow Up type or no follow up needed, obviously I don't really want them to pick No follow Up needed before completing the call as otherwise they would most likely keep this status and not schedule a follow up

I hope this makes sense?

Thanks for any advice you can give.

 

Adam

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Conor Gallagher Profile Picture
    715 on at

    I would do this using a plugin, because it's not always a required field. The problem is that the only way you can capture and hook into the completing of a phone call is via a plugin.

    If I recall correctly you need to hook into the Pre event of SetStateDynamic or something like that. Then check what they've set in your required field and if it's not a valid setting throw an exception.

  • Suggested answer
    GL-23071537-0 Profile Picture
    on at

    Hi Adam,

    I believe this can also be done with JavaScript on save of the phone call, check if Status is completed, then prompt the user.

  • AdamBrown55 Profile Picture
    895 on at

    Thank you for coming back to me.

    I'm not entirely sure how to do this, is it entered in the Phone Call Entity Form Properties Window? or does the Javascript need to be entered elseware?

  • Conor Gallagher Profile Picture
    715 on at

    Gretchen is correct, you can achieve this via JavaScript (I didn't know the Mark as complete triggered the OnSave event!)

    You need to trigger a javascript function in the OnSave event of the form. Take a look at this blog post, it will guide you how to do this:

    blogs.infinite-x.net/.../crm-2011-canceling-the-save-operation

  • Mark Spiers Profile Picture
    1,085 on at

    Conor has the slightly more correct answer,

    yes it can be done with both javascript and using a plugin.

    however here is the difference.

    A plugin will fire no matter how the field gets updated (configurable), webserice endpoint, web client, outlook etc.

    javascript will ONLY fire on webclient/outlook (But, (and correct me if i am mistaken) i believe NOT during outlook offline playback mode ).

    so, if you use offline mode, or have other ways of updating this field that is not on the webclient, then i would advise a plugin.

    if you only use the webclient/outlook online mode then i would also suggest javascript.

    Regards,

    Mark

  • AdamBrown55 Profile Picture
    895 on at

    Hi we are using webclient only so think JScript would be ok, I am not used to using JScript as most of my previous work has been in VB but I am adding the code below to a new .js library.

    Does this seem right?


    function Form_onsave(executionObj)
    {
        var shouldSave = if(New_FollowUpType = '')

        if (shouldSave)
        {
            if(Status = ‘Completed’)
    {
    alert("Please Provide a Follow Up.");

            executionObj.getEventArgs().preventDefault();
    }   
          }
    }

    Thanks

    Adam

  • Conor Gallagher Profile Picture
    715 on at

    Not quite. When accessing attributes on the form you need to go through the Xrm object to get the attributes, something like this:

     

    Xrm.Page.getAttribute('New_FollowUpType').getValue() ;

     

    Unfortunately you need to be a bit smarter about the state, because if you look up the statecode attribute it will still say "0" which means it's open. This is because your event is firing at the validation stage so the status hasn't updated yet. Instead you must check if  the event.Mode is 58 (which is Save as Complete). Here's some reference material on the Form OnSave you might find useful: http://msdn.microsoft.com/en-us/library/cc150868.aspx

  • AdamBrown55 Profile Picture
    895 on at

    Ok, From Looking around the help pages you suggested I have come to this:

    function Form_onsave(executionObj)
    {
        if(crmForm.getAttribute('New_FollowUpType').getValue(); = '')
        {
            if(crmForm.event.mode;  = 58)
    {
    alert("Please Provide a Follow Up.");

            executionObj.getEventArgs().preventDefault();
    }   
          }
    }

    They say that you can use the crmForm reference as it is refering to its own entity, Is this right? or should I enter it like var shouldSave = if(Xrm.Page.getAttribute('New_FollowUpType').getValue() ; = '')

  • Conor Gallagher Profile Picture
    715 on at

    Actually, crmForm is a CRM 4.0 object and only exists for backward compatibility. It's my fault you came across this as now I notice I linked you to the CRM 4.0 version of the SDK reference by mistake!

    For CRM 2011 version of the sdk reference see here instead. I've linked directly to Form Scripting which is a similar page in the CRM 2011 reference: msdn.microsoft.com/.../jj602964.aspx

  • AdamBrown55 Profile Picture
    895 on at

    Think perhaps this is just going to be a bit beyond me at the moment, I entered the code

    function Form_onsave(executionObj)
    {
    •     var shouldSave = if(Xrm.Page.getAttribute(“New_FollowUpType”).getValue() ; = '')

        if (shouldSave)
        {
            if(Xrm.Page.event.mode;  = 58)
    {
    alert("Please Provide a Follow Up.");

            executionObj.getEventArgs().preventDefault();
    }   
          }
    }

    into the Web Resource Content box on the entity form but eneded up getting the following error when opening the form (And again when trying to complete the call. 

    "There was an error with this field's customized event"

    Field: Window

    Event: Onload

    Error: Object Expected

     

    Think I may have to abandon this as I am obviously having an affect on other areas of the code, Maybe to do with creating a second .js Library? So learning a new system and a new language at the same time may have been a bit too much.

    Thanks anyay.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans