Dynamic xpath need to be called in the code

I get random id always when i run the code (randompincode),
i need to send that random id to xpath and with that xpath i need to get the text of an element
for ex:- RandomPincode = ‘8522’
WebUI.setText(findTestObject(‘Object Repository/History/SearchTab_InHistorySelection’), RandomPincode)
String xpath = ‘//div[text()=’+RandomPincode+‘]/preceding-sibling::div[10]’
TestObject to = new TestObject("object_name ")
to.addProperty(“xpath”,ConditionType.EQUALS,xpath)

xpath added in object repos :-
object_name =
//div[text()=‘${RandomPincode}’]/preceding-sibling::div[7]

How about trying your code by enclosing your variable with the dollar sign and curly parentheses, like below (and within double quotes, too)?

Also, when you put code into this forum, put three back ticks, like ``` , above and below your code. The back tick is found on the same keyboard key as the tilde, like ~