Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

How to solve 'Attribute : .......cannot be set to null' error

Posted on by Microsoft Employee

I am setting 'statecode' field of entity 'quote' of CRM using script component in ssis as:

if(!Row.activated_IsNull)
        {
            quote.Attributes["statecode"] = Row.activated;
        }
        else
        {
            quote.Attributes["statecode"] = null;
        }

But I am getting following error when I run the it:

pastedimage1650278861287v1.png

What can be the reason for this. Please help!!

Thanks in advance.

Categories:
  • Guido Preite Profile Picture
    Guido Preite 54,065 Moderator on at
    RE: How to solve 'Attribute : .......cannot be set to null' error

    I wrote "is like an optionset", I know that statecode has a specific type to itself but doesn't change the fact that there is a numeric value behind. I don't know how to set it inside the SSIS script you are writing, check how can you set an optionset field inside the ssis script, setting statecode will be nearly the same

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to solve 'Attribute : .......cannot be set to null' error

     Guido Preite 

    In my case the datatype of statecode is 'Status' and not optionset. How do I assign that in SSIS script

  • Guido Preite Profile Picture
    Guido Preite 54,065 Moderator on at
    RE: How to solve 'Attribute : .......cannot be set to null' error

    statecode is like an optionset, you need to set it as an optionset (so with a numeric value behind), not as a string, and "Draft" is definitely not a valid state. Check the statecode from the metadata (usually Active is 0 and Inactive is 1) and see how you should set it inside the SSIS script you are writing.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to solve 'Attribute : .......cannot be set to null' error

    Guido Preite

    I wrote following code but still throws same error:

    if(Row.activated == 1)

           {

               quote.Attributes["statecode"] = "Active";

           }

           else if (Row.activated == 0)

           {

               quote.Attributes["statecode"] = "Draft";

           }

  • Guido Preite Profile Picture
    Guido Preite 54,065 Moderator on at
    RE: How to solve 'Attribute : .......cannot be set to null' error

    statecode is for most entities just Active and Inactive, so if the record is not Active (as you are setting in the if condition) then is Inactive

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to solve 'Attribute : .......cannot be set to null' error

    Guido Preite

    Doe that mean I have to hard code it?

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,065 Moderator on at
    RE: How to solve 'Attribute : .......cannot be set to null' error

    the reason is the error message you are receiving, you can't set that field to null, you need to put one of the valid values

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,564 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,651 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans