How to define dynamic selector (modify selector string from workflow)?

I would like to read cells from MS Project one by one (reading table does not work, only get full text for cell). Problem is that each cell has a name like “cell(1,3)”. This reference is located in selector for this cell.

I would like to iterate through <ctrl name=‘(i,3)’ role ‘cell’ /> where i is simply row number.
Is it possible? If yes, how to do this?
regards
Andrzej

@Andrzej,

Provided if you have this in your selector, we can add a variable as follows.
"<ctrl name='(" + i.ToString + ",3)' role 'cell'"

Regards,
Dominic :slight_smile:

Hi,

Yes it’s it possible @Andrzej.

First create one int variable(intCellnumber) and string variable(strElement).
IntCellnumber=1

StreElement=“<ctrl name=’(”+intCellnumber.Tostring()+“,3)’ role ‘cell’ />”

Loop through it.

Regards,
Arivu

@arivu96, @Dominic
Thank you very much for fast help. Actually I had this in mind, but my problem was I was trying to edit statement in Selector window, where there is syntax checker - checks for HTML conformance. When I put the string to control on the right - it worked.
Have a nice weekend! :slight_smile:
Andrzej

1 Like

@arivu96, @Dominic
I have put to selector variable strSelector with body as follows:
“<ctrl name=’(”+ID.ToString()+“,3)’ role=‘cell’ />”.
Using MessageBox I print value of strSelector and it is:
“”+“”+“” - without quotes.
Earlier in my flow I read this cell using static definition to make sure it is readable - with no errors.
At step which uses dynamic selector I get an exception:
An error has occured

Source: System.Xml

Message: Unable to cast object of type ‘Newtonsoft.Json.Linq.JValue’ to type ‘System.String’.

Exception Type: InvalidCastException

System.InvalidCastException: Unable to cast object of type ‘Newtonsoft.Json.Linq.JValue’ to type ‘System.String’.
at System.Xml.XmlException…ctor(SerializationInfo info, StreamingContext context)
at Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)(Object )
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializableItem(JToken token, Type type, JsonISerializableContract contract, JsonProperty member)
at Newtonsoft.Json.Serialization.JsonFormatterConverter.Convert(Object value, Type type)
at System.Runtime.Serialization.SerializationInfo.GetValue(String name, Type type)
at System.Exception…ctor(SerializationInfo info, StreamingContext context)
at Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)(Object )
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at UiPath.Shared.JsonParser.DeserializeObject[T](String jsonValue)
at UiPath.Models.UiPathDuplexProxy.<>c__DisplayClass21_0.b__0()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
Any ideas?
regards
Andrzej

@Andrzej, This could be variable ID that you are using is in different format (here JSON Jvalue ). Can you share screenshot/ Xaml for better understanding ?
Regards,
Dominic :slight_smile:

strSelector
the value shown by MessageBox


regards
Andrzej

BTW - body I have put above was cut. Whole value is visible on screen shot.

Hi,
@Andrzej

I am not sure y u r getting this issue, but I am sure it’s not related to selector issue, can you change the (cell) variable type “generic” to " string" and try it.

Regards,
Arivu

Here you are:
The workflow has validation errors. Review and resolve them first.

System.Activities.InvalidWorkflowException: The workflow has validation errors. Review and resolve them first. —> System.Activities.ValidationException: Compiler error(s) encountered processing expression “Cell”.Invalid L-value expression.:Reference expressions cannot end with Conversion. The provided expression’s type must exactly match the type T of VisualBasicReference or LambdaReference.
— End of inner exception stack trace —

Exactly the same error appears in step Get Full Text with static selector.
regards
Andrzej

Hi @Andrzej,

Initial conversation you said if u have that selector getting the output now u r telling static also not working…so please tell clearly…find the selector using uiexplorer.

Regards,
Arivu

I have two Get Full Text steps which read the same cell from MS Project.
One has static selector exactly the same as shown above in screen shot from Messagebox.
Second has dynamic selector defined by variable strSelector as shown in big screen shot.
I assign value ID = 2 and then strSelector as shown in screen shot 3 - Value(InArgument).
after value is assigned to strSelector I view it using MessageBox - it seems to be identical to static selector value.
Both Get Full Text steps refer then to the same cell (2,3).
Also both steps have output defined to variable Cell variant.
I cannot define this variable as String, because it causes validation exception.
I hope it is now more clear.
regards
Andrzej


UiExplorer view.
regards
Andrzej

Hi @Andrzej,

Try it…
Use the selector for all (4 lines) what u r getting in the ui explore…and try it…I hope in right side “text” field value only u want, its right???

If yes go to get attribute activity.
Else go normally

Regards,
Arivu

1 Like

Hello @arivu96,
I have added values visible in 3rd and 6th position on UIExplorer screen shot.
Now I can iterate through rows as required and I have checked this twice to make sure it works.
Many thanks!
Have a nice day
Andrzej