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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Set the value of a field by default ?

(1) ShareShare
ReportReport
Posted on by 81
Hi everyone, I'm in a transfer order trying to set a default value on a field. The problem that arises is that when starting the form, it starts with the value correctly but it is not inserted in the field but instead appears as in editing mode, so it is not as if the value had not yet been inserted and validated.
Any ideas on how to correctly process this situation? What would I be missing? I appreciate your contributions.
I do it from the form control, then from an eventHandler, but in both cases I have the same result.
 
    [FormDataSourceEventHandler(formDataSourceStr(StrategicTransferOrders, InventTransferTable), FormDataSourceEventType::InitValue)]
    public static void InventTransferTable_OnInitValue(FormDataSource sender, FormDataSourceEventArgs e)
    {
    
        InventTransferTable inventTransferTable = sender.cursor() as InventTransferTable;
        FormRun form = sender.formRun();
        
        RecId employmentRecId;
        HcmWorkerRecId workerRecId = HcmWorkerLookup::currentWorker();
        employmentRecId = HcmEmployment::findByWorkerLegalEntity(workerRecId,CompanyInfo::current()).RecId;
    
        if (!inventTransferTable.InventLocationIdFrom)
        {
            inventTransferTable.InventLocationIdFrom = HcmEmploymentDetail::findByEmployment(employmentRecId).InventLocationIdOrigin;
        }
    }
 
I have the same question (0)
  • Layan Jwei Profile Picture
    8,282 Super User 2026 Season 1 on at
    Hi,

    In what methods did u write this code? can you show us full code please?
  • AR-16051714-0 Profile Picture
    81 on at
    Hi Layan, I just updated the post. I am using the onInit eventHandler to set the value, the value is placed correctly, but it is not embedded and validated, it is only superficially as if it were still being edited, it is not recorded in the field.
  • Layan Jwei Profile Picture
    8,282 Super User 2026 Season 1 on at
    Hi,
     
    It's not working even if u click save on the form?
  • AR-16051714-0 Profile Picture
    81 on at
    Yes, in that case yes, that is the problem, it is only stored if I click on the value again, then it does take it and store it, but the idea is that I would like this not to be the case, that the user does not have you have to click on the value but it is already stored at the time the form is started
  • Layan Jwei Profile Picture
    8,282 Super User 2026 Season 1 on at
    Hi,
     
    Sorry I'm not sure what do you mean by it's saved when you click on it again.
     
    Init value gets called once u click create new record, it default some fields as a start and the whole record is not created until you click save. So i'm not sure what is ur issue exactly as this is how it works
     
    Maybe share a screenshot?

    If you would like the value to be filled once u open the form and not when the record is created, then u can use init method instead
  • Martin Dráb Profile Picture
    240,189 Most Valuable Professional on at
    Calling refresh() method of the form data source (sender.refresh() in this case) will likely solve your problem.
  • Layan Jwei Profile Picture
    8,282 Super User 2026 Season 1 on at
    Hi,

    Is your issue fixed? or do you still need help?

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 382 Super User 2026 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 265 Most Valuable Professional

#3
Subra Profile Picture

Subra 262

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans