Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Converting array to st...
Finance forum
Answered

Converting array to str and storing in a field

editSubscribe (2) ShareShare
ReportReport
Posted on by 64
////Hi Team,
 
I have created a custom entity for whsinventtable and created a virtual field called strfilterCode. In postload method, I want to store filtercode array field value to this virtual field. How can I convert array to str and store in this virtual field? Please help.
  • Karuna Dogra Profile Picture
    Karuna Dogra 64 on at
    Converting array to str and storing in a field
    That worked. Thanks a lot Martin (The Genius). This thread can be closed. 
     
    regards
    Karuna
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 223,155 Super User on at
    Converting array to str and storing in a field
    It's trivial - you just need a condition to skip adding the separator if the filter code value is empty. For instance:
    for (int i = 1; i <= dimOf(whsInventTable.FilterCode); i++)
    {
        str filterCode = whsInventTable.FilterCode[i];
    
        if (filterCode && this.StrFilterCode)
        {
            this.StrFilterCode += ',';
        }
    
        this.StrFilterCode += filterCode;
    }
  • Karuna Dogra Profile Picture
    Karuna Dogra 64 on at
    Converting array to str and storing in a field
    Thank you so much Martin, that works. Also, I have been trying to mark that check box does this question your answer but its just keep buffering.
     
    Can you please also guide, how I can avoid extra comma in the string field StrFilterCode in case out of 5 indexes (Filter code 1, Filter code 2, Filter code 3....) only one index has value? It is storing the value like this  Item1,,,,
     
    Please guide.
     
    Thank you
  • Martin Dráb Profile Picture
    Martin Dráb 223,155 Super User on at
    Converting array to str and storing in a field
    FilterCode is an array field, not a container.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,487 Super User on at
    Converting array to str and storing in a field
    Are you saying you have a container value to be stored in a string field? If yes, then you can make use of standard con2str() and pass any delimiters if you need. 
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 223,155 Super User on at
    Converting array to str and storing in a field
    Do you want values separated by a delimiter?
     
    You could use something like this:
    for (int i = 1; i <= dimOf(whsInventTable.FilterCode); i++)
    {
        if (this.StrFilterCode)
        {
            this.StrFilterCode += ',';
        }
    
        this.StrFilterCode += whsInventTable.FilterCode[i];
    }
    

Helpful resources

Quick Links

Take the Community feedback survey!

Answer this brief 15-question survey about your Community experience…

Demystifying Copilot: Service Edition with Sundar Raghavan

Sundar answers more questions about Copilot for Service...

Dynamics 365 Business Central vs Finance and SCM

Take a look at the key differences between Business Central and…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,361 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,155 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,140

Featured topics

Product updates

Dynamics 365 release plans