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

Community site session details

Session Id :
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.

I have the same question (0)
  • Suggested answer
    Ankit Sabharwal Profile Picture
    on at
    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.

  • UberMunchkin Profile Picture
    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
    Ankit Sabharwal Profile Picture
    on at
    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.

  • Suggested answer
    Ankit Sabharwal Profile Picture
    on at
    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.

  • Paul_Owen Profile Picture
    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

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 74 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 62 Most Valuable Professional

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 57

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans