Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

More Javascript Problems with the new Model

(0) ShareShare
ReportReport
Posted on by 10

Hi folks, 

So I have been tasked with moving our Dynamics system over to the unified interface, I am trying to support a lot of javascript based things which I did not design and don't understand that well.  I am currently having an extremely frustrating problem with a script that is supposed to pop a warning notification on the contact form if the contact has a value of "Yes" in the field for 'Criminal Record?'.  But it just won't work and I cannot see what the problem is.

Here's the script:

function alertCriminal(executionContext) {

var formContext = executionContext.getFormContext();
var frm = formContext.ui.formSelector.getCurrentItem();
var objText = formContext.getAttribute("new_criminalconvictions").getText();
var warningType = "INFO";
var warningMessage = "Student Has Criminal Conviction";

if (frm != null) {

var formLabel = frm.getLabel();

if (formLabel.toUpperCase() == "CONTACT") {
if(objText == "Yes") {
formContext.ui.setFormNotification(warningMessage, warningType);
}
}


}

}

(And yes, I have checked that the execution context is set to be passed correctly in the form configuration)

Whenever I try to load the form I get this error:

TypeError: formContext.getAttribute(...).getText is not a function

I have checked the line it refers to so many times and I cannot say the problem, I've setup the code exactly as it says in the reference:

var objText = formContext.getAttribute("new_criminalconvictions").getText();

Any help would be greatly appreciated as this is making me want to throw my laptop out the window in frustration.

  • Paul_Owen Profile Picture
    Paul_Owen 2,027 on at
    RE: More Javascript Problems with the new Model

    The value will be either True or False, True = Yes, False = No

    Regards

    Paul

  • Suggested answer
    RE: More Javascript Problems with the new Model

    Also for normal option set, I have used below command :-

     var at = formContext.getAttribute("new_optionset")

    alert(at.getText());

    above code works fine for me. My trial instance is on build version : 9.1.0000.12926

    I have tested it on UCI. Can you please also state the version.

  • Suggested answer
    RE: More Javascript Problems with the new Model

    Hy Partner,

    Thanks for replying back.

    Optionset label we have to retrieve, then we an do that through javascript :

    var objText = formContext.getAttribute("new_criminalconvictions").getValueInternal().label in UCI. This will help you. I have tried this in my trial instance. I have used two options set field which have value Yes or no.

    It might help you out.

    Hope this helps.

    Best regards,

    Ankit

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • UberMunchkin Profile Picture
    UberMunchkin 10 on at
    RE: More Javascript Problems with the new Model

    Hi, sorry, I do not understand what you are suggesting.

    I don't want the Value of the field (as it is a yes/no optionset), I need to know the text so I can determine yes/no.

    The line of code you have suggested above returns the value, not the text and so does not work.

  • Suggested answer
    RE: More Javascript Problems with the new Model

    Hy Partner,

    Hope this post finds you well.

    In UCI please perform below step :-

    var objText = formContext.getAttribute("new_criminalconvictions").getValue();

    Use above function and please get back on top of this

    Hope this helps.

    Best regards,

    Ankit

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,684 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,414 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans