Hello, How to convert object variabe to string
My object variable cc is like this and when i convert that .toString then it changed like this.
Hi @rajat_dhammi,
Probably you need the properties of this object as String.
So, access it first and then convert it to String.
Example: cc.Description.ToString
Sorry Rajat
Try cc.FieldUrlValue.Description.ToString
Is this object a custom one?
Could you share your project?
Donât need to be the whole project, just a simple sequence with this object variable declaration, the assign to cc variable and what you need to do before to be able to assign.
Got itâŚ
I need to check your project. A simple sequence containing this part you mentioned above is enough.
Be sure to delete sensitive data, if applicable.
Convert type of cc variable to string in variables tab, and then assign
cc= item(âContentCaleâ).To string
It would be item(âContentCalendarURLâ).ToString
Looks like u just mentioned item(âContentCalendarURLâ)
Please add .To string and try
@User12
Giving wrong value if change cc to string
cc is object variable and cc1 is string, with string got completely wrong output
Hi, did you manage to resolve this? If not, please let me take a shot at it.
From what Iâve seen in this thread:
- I think @gustavo.cervelin suggests the correct method (cc.Description.ToString should be correct, cc.FieldUrlValue.Description.ToString wonât work as that calls to a second FieldUrlValue object within the first one FieldUrlValue members (Microsoft.SharePoint.Client) | Microsoft Learn
- I think @User12âs method wonât work here as you need only 1 property out of the object, not the whole object as a string (if I interpreted your question correctly)
- Iâm taking a couple of guesses here based on my understanding of the inner workings of VB/UiPath. If anyone can correct me or describe more accurately, please educate me!
- If anything I wrote made sense or was useful, please let me know. It teaches me how to teach others
Things you could try:
- In reply 1 below you are trying to assign the property.tostring to a message box. Iâve noticed that sometimes (there probably are people here who are smarter than me that can explain exactly why) UiPath doesnât like when you convert (.ToString is a conversion to String type) and assign at the same time, and then use that value immediately (like you: you want to display it in a message box). You could try assigning cc.Description.ToString to a string variable, and then assign the string variable to the message box.
- You could try getting the value directly from the item (without assigning it to cc first). Try creating a string variable, and assigning
item("ContentCalendarURL").Description.ToString
. - If this doesnât work you could try assigning cc.Description (without the .ToString) to a generic type variable, and then assign that generic value to the message box. This might either work (as the generic var will be automatically converted to whatever you need it to be, I think this is called âimplicit conversionâ). It might also not work, but the error message might show you why ("Compiler error(s): Option Strict On disallows implicit conversions from âXâ to âStringâ). âXâ would tell you which type of data comes from the cc.Description.
Reply 1:
Iâve noticed in this thread that youâre changing around multiple things while debugging. Best practice if you want to debug is to change only one thing at the time, and keep all others the same. This way you can analyze the results of your actions much better (I know this is hard, I always fall for the same trap because Iâm just trying different things). Example:
In this reply you change both the assign activity that you want to do (Assign instead of Message Box activity) and the value that you want to assign to it. This makes it much harder to understand and compare the results you are getting.
Did you resolve this issue? Been trying to archieve the same as you, but without succes.