Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to assign null val...
Finance forum
Suggested answer

How to assign null value to string parameter using contract class

Posted on by 3,039
Hi All,
 
I have created contract class which consist string parm method. I am using this contract class for JSON searilization and then passing data to third party application. As per the requirement all the blank string values should be assign null value and json output should be like:
 
{
/name/: null
 
I have tried passing null value to method in the case output is coming like as below:
{
/name/:/ /
}
 
Please guide how I can achieve this. Thanks. 
Categories:
  • Martin Dráb Profile Picture
    Martin Dráb 224,750 Super User on at
    How to assign null value to string parameter using contract class
    If your methodname() method accepts str type and the backing variable is str too, it can't store null values. I don't know whether changing it to System.String will work, but it definitely can't work with str.
  • Pooja Karki Profile Picture
    Pooja Karki 3,039 on at
    How to assign null value to string parameter using contract class
    Yes, I have tried passing value like:
     
    classname.methodname(CLRInterop::Null("Null"));
     
    in this case it is returning blank value.
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 3,050 on at
    How to assign null value to string parameter using contract class
    Hi,
     
    Did you try to set the string with "null", give it a try and tell us the result.
     
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
  • Pooja Karki Profile Picture
    Pooja Karki 3,039 on at
    How to assign null value to string parameter using contract class
    I have tried below line and it is returning blank output.
     
    CLRInterop::Null("System.String");
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 3,050 on at
    How to assign null value to string parameter using contract class
    Hi,
     
    Try the below code:
    static void Job5(Args _args) 
    { 
        System.String nullStr; 
        nullStr = CLRInterop::Null("System.String"); 
        print CLRInterop::isInitialized(nullStr); 
        print CLRInterop::isNull(nullStr); 
    }
    Based on this document:
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,663 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,750 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans