Actually, In a book we are using text variables in the running header using Chapter Title Paragraph styles for Chapters.
But when the backmatter (i.e., Bibliography, Index etc) occurs text variable has to take backmatter heading style (i.e., BMH).
You are trying to change the value of one single occurrence of a text variable with a script? That's not possible, just like it is not in the UI itself.
(It is possible, since you can change the value of a Custom Text Variable -- but that would change all occurrences of it, not just one.)
A possible workaround: create another text variable.
Why don't you use a different master spread for things like that?
Thank you very much for your helpful reply.