Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

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

(0) ShareShare
ReportReport
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.

  • Guido Preite Profile Picture
    Guido Preite 54,087 Super User 2024 Season 1 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,087 Super User 2024 Season 1 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,087 Super User 2024 Season 1 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,087 Super User 2024 Season 1 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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans