Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Saving form before setting all my fields on form required

(0) ShareShare
ReportReport
Posted on by 1,290

Hello All,

I have a following requirement where on the click of button in the ribbon, there are around 20 fields should be converted to "Business Required" on the form. Currently these fields are "Business Recommended".

However, I would also like to save the form before setting them required.

I am able to set the 20 fields to "Business Required" but because the fields are required it wont save the form.

For Example: 

I am filling out the form and i have filled out 7 fields details and I would like to save those 7 fields information on the click of the Submit button. Below is the JS code which i am using to convert the fields into business required. But i am having hard time saving the records. 

function setRequiredLevel(primaryControl)
{ debugger;
var formContext = primaryControl;
formContext.data.entity.save();
afterSave(formContext);
}
function afterSave(formContext)
{

var currentForm = formContext.ui.formSelector.getCurrentItem();
if(currentForm.getLabel() == "Commercial Form"){
var intakeFields = ["ibc_opportunitytoahaintakeid",
"ibc_lineofbusiness",
"ibc_statusofrequest",
"ibc_dateofinitialintakeformsubmission",
"ibc_duedate",
"ibc_effectivedate"];
}

for(var i=0; i<intakeFields.length; i++)
{
var intakeField = intakeFields[i];
if(formContext.getAttribute(intakeField) != null)
{
formContext.data.entity.save();
formContext.getAttribute(intakeField).setRequiredLevel("required");
}
else
{
formContext.getAttribute(intakeField).setRequiredLevel("required");
}

}

}

Please let me know if there's any workaround where i can save the form first, so i dont lose the information in the fields which i have already filled

Any help would be much appreciated.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,961 Moderator on at
    RE: Saving form before setting all my fields on form required

    HI,

    You can update the record with field data using Web API and this way you don't have to take care of mandatory field error validation.

    Once you save the data using web api then make those field mandatory.

    If found helpful, Please mark my answer verified.

  • Suggested answer
    Gilmeyer Profile Picture
    Gilmeyer on at
    RE: Saving form before setting all my fields on form required

    Hi,

    Please use the following save method docs.microsoft.com/.../save and on success callback try to make the the empty fields business required.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans