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 :
Finance | Project Operations, Human Resources, ...
Answered

DataEntity - reason for clearing out isFieldSet

(0) ShareShare
ReportReport
Posted on by 678

Hi All,

As far as I am concerned, 'isFieldSet' method of a data entity is to check to see if the field is returned by the connector. 

* If the field specified by field_name is returned by the Connector, returns a Boolean True.
* If the field specified by field_name is not returned by the Connector, returns a Boolean False.

In some of methods in data entities, it is trying to clear out 'isFieldSet' method like below example.

What is the detailed reason for this? 

public void initializeEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
    super(_entityCtx, _dataSourceCtx);

    switch (_dataSourceCtx.name())
    {
        case dataEntityDataSourceStr(PurchPurchaseOrderHeaderV2Entity, PurchTable):
            // clear out 'isFieldSet' so the defaulting logic does not consider fields that were set by initValue as specified by the user
            _dataSourceCtx.setAllFieldStatesToNotSet();
            break;
    }
}

/// 
/// Sets field state for all fields to the "Not set" value.
/// 
/// The data source context.
public static void setAllFieldStatesToNotSet(DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
    _dataSourceCtx.setFieldStateForAllFields(FieldState::NotSet);
}

Thank you. 

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    My understanding of "isFieldSet" is that it's used in data import to determine whether a field value was provided. Not sure if it's also provided in the export.

    It seems that the code comment in line 8 explains why it's used in your particular example.

    docs.microsoft.com/.../system-tables

    "isFieldSet Checks whether a field has a Set or Defaulted state."

  • ShawnDEV Profile Picture
    678 on at

    Hi Do you mean that isFieldSet is used in data import scenarios only? not in OData secenario? 

    public void defaultField(FieldId _fieldId)
    {
    	super(_fieldId);
    
    	switch (_fieldId)
    	{
    		case fieldNum(InventInventoryTagCountingJournalLineEntity, InventorySiteId):
    			if (this.isFieldSet(fieldNum(InventInventoryTagCountingJournalLineEntity, WarehouseId)))
    			{
    				this.InventorySiteId = InventLocation::find(this.WarehouseId).InventSiteId;
    			}
    			break;
    	}
    }

    Thank you.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    You could debug OData export and find out. Please share your findings with us. Thanks! 

  • Verified answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    The logic should be the same in both data management and OData.

  • ShawnDEV Profile Picture
    678 on at

    Hi all,

    Going back to the basic, the base Enum FieldState can have three literals: NotSet,Set and Defaulted.

    What does it mean that field state is set, NotSet or Defaulted. Any specific example to understand this concept?

    Thank you.

  • Verified answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Set - set explicitly

    Defaulted - set implicitly by defaulting logic

    NotSet - not set

  • ShawnDEV Profile Picture
    678 on at

    Hi,

    In case a field is 'Set' state,  

    does that mean that a field value is set (or returned from the source) or only just a field whether the field value is contained or not?

    Thank you.

  • Verified answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    If it was just about the value, the state wouldn't be needed at all. You would simply check the value.

    Imagine this scenario: A value is empty and I want to set the field to a default value only if it's empty because it wasn't provided at all. If it was explicitly provided as empty, I don't want to overwrite it with a default value.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans