Options

How can I convert C/AL decimal type to .NET string type?

undy0602undy0602 Member Posts: 67
Hello All,
I have to use .NET assembley in NAV. But I cant put data into .NET string type.
How can I convert C/AL decimal type to .NET string type? also from .NET string into C/AL decimal/text

Regards,
Undy

Answers

  • Options
    andrewtandrewt Member Posts: 73
    Hi undy,
    have you already checked out built-in data type mapping between C/AL and .NET ?

    As per
    https://msdn.microsoft.com/en-us/library/hh165619(v=nav.90).aspx
    C/AL strings can be mapped to .NET strings directly.
    So a simple convert of your C/AL decimal into C/AL string by using FORMAT should do the trick...
    Variables:
    NAVDecimal	Decimal		
    DotNetString	DotNet	System.String.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    
    NAVDecimal := 1.2345;
    DotNetString := FORMAT(NAVDecimal);
    MESSAGE('%1',DotNetString);
    

    Hope this helps
    Andrew T.
  • Options
    undy0602undy0602 Member Posts: 67
    Thanks Andrew T.
    I`ve already tried that. But it appears dont match types. Is there any reason for this?

    Regards,
    Undy
  • Options
    andrewtandrewt Member Posts: 73
    Difficult to say without knowing your .NET assembly. I would assume it doesn't provide a simple string datatype but something more complex as a first guess. For instance you won't be able to autoconvert if your .NET datatype has a nullable datatype.
    I would suggest to check your .NET datatypes. Have a look at the constructors and methods of the .NET variables displayed on your C/AL Symbols and try to identify its data type.

    Andrew T.
  • Options
    undy0602undy0602 Member Posts: 67
    Thanks Andrew
    I try to integrate to other system using this assembly so I dont know about that well.
    I only know fields and data type. Functions return by JSON Ustring data type.

  • Options
    andrewtandrewt Member Posts: 73
    Ok, sounds like my initial assumption is correct then. The JSON Ustring datatype seems to cause the problem here as it doesn't seem to be based of the simple .NET datatype System.string so you cannot apply the integrated data mapping provided by NAV's .NET interop.
    As I do not have any experience with JSON data type integration into NAV I cannot help you any further but initially you would have to find out how to deal with this JSON string datatype in NAV.
    Just an idea - can you assign it to a .NET variable of type System.string ?

    Cheers
    Andrew T.
Sign In or Register to comment.