Help required: CSS and context (variable) access

I have a button which is CSS coded to this:

<div id="regular_x">
   <md-button class="md-button program-names teal"
    data-topic="1"
    data-payload="152">Penn and Teller (Sunday night)
   </md-button>
</div>

<script>

(function($scope) {

$('#regular_x').on('click', function(e) {
    e.preventDefault(); //prevent default behavior
    $scope.send({"topic":"momentary_regular","payload": 152});
});
    
})(scope);
</script>

Which is good, (but now looking at it is not the best. I'll get back to that soon I hope.)

But the 152 is (now) variable.

How do I make it that the code access either a flow or global context?

This is another button's code which I saw is different:

<div id="regular_2">
   <md-button class="md-button program-names teal">Spicks and Specks (Daily)
   </md-button>
</div>

<script>

(function($scope) {

$('#regular_2').on('click', function(e) {
    e.preventDefault(); //prevent default behavior
    $scope.send({"topic":"momentary_regular","payload": 152});
});
    
})(scope);
</script>

In both I don't need the <script> part do I?
Though I would have to modify the second one to have the line in with the
data-payload="152" line.....

Forgive the dumb question.
I've been away from the machine for 2 weeks and the withdrawal is painful.

Update:

Ok, I was wrong (When aren't I?)

This is the code for the button:

<div id="regular_x">
   <md-button class="md-button program-names teal">What ever
   </md-button>
</div>

<script>

(function($scope) {

$('#regular_x').on('click', function(e) {
    e.preventDefault(); //prevent default behavior
    $scope.send({"topic":"momentary_regular","payload": 152});
});
    
})(scope);
</script>

The 152 needs to be in context and gettable by this code.

Unless things have changed, you cant access it directly, you have to send it in as a message

^&&(*&%($& Above my skill set.

That is going to make things really difficult then.

I just hope that the assisiations aren't going to change again.
Just that having one thing to change rather than 30 nodes will make it a lot easier.

Is there a way I could (say) lookup the name?

So, the node as is, sends the name (say abc) and it goes through another node that searches the flow context and if a match is found, returns the value?

Something along the line of the vlookup() command in spreadsheets.

(Sorry)

So expanding on what I just said:

This is the flow - as an example.

[{"id":"1dd69628.a44192","type":"change","z":"88de1ac2.8b8c38","name":"ALL channels used (name/number) *","rules":[{"t":"set","p":"nine","pt":"flow","to":"100","tot":"num"},{"t":"set","p":"fox1","pt":"flow","to":"101","tot":"num"},{"t":"set","p":"abc","pt":"flow","to":"102","tot":"num"},{"t":"set","p":"sbs","pt":"flow","to":"104","tot":"num"},{"t":"set","p":"uktv","pt":"flow","to":"105","tot":"num"},{"t":"set","p":"seven","pt":"flow","to":"107","tot":"num"},{"t":"set","p":"fox8","pt":"flow","to":"108","tot":"num"},{"t":"set","p":"ten","pt":"flow","to":"110","tot":"num"},{"t":"set","p":"showcase","pt":"flow","to":"112","tot":"num"},{"t":"set","p":"sifi","pt":"flow","to":"116","tot":"num"},{"t":"set","p":"classic","pt":"flow","to":"117","tot":"num"},{"t":"set","p":"bbcfirst","pt":"flow","to":"119","tot":"num"},{"t":"set","p":"universal","pt":"flow","to":"120","tot":"num"},{"t":"set","p":"history","pt":"flow","to":"130","tot":"num"},{"t":"set","p":"discovery","pt":"flow","to":"133","tot":"num"},{"t":"set","p":"natgeo","pt":"flow","to":"139","tot":"num"},{"t":"set","p":"boxsets","pt":"flow","to":"150","tot":"str"},{"t":"set","p":"abccomedy","pt":"flow","to":"152","tot":"num"},{"t":"set","p":"seven2","pt":"flow","to":"156","tot":"num"},{"t":"set","p":"sevenmate","pt":"flow","to":"157","tot":"num"},{"t":"set","p":"sevenflix","pt":"flow","to":"158","tot":"num"},{"t":"set","p":"ninego","pt":"flow","to":"162","tot":"num"},{"t":"set","p":"ninegem","pt":"flow","to":"164","tot":"num"},{"t":"set","p":"viceland","pt":"flow","to":"170","tot":"num"},{"t":"set","p":"fox1-plus2","pt":"flow","to":"201","tot":"num"},{"t":"set","p":"uktv-plus2","pt":"flow","to":"205","tot":"num"},{"t":"set","p":"fox8-plus2","pt":"flow","to":"208","tot":"num"},{"t":"set","p":"showcase-plus2","pt":"flow","to":"212","tot":"num"},{"t":"set","p":"sifi-plus2","pt":"flow","to":"216","tot":"num"},{"t":"set","p":"classic-plus2","pt":"flow","to":"217","tot":"num"},{"t":"set","p":"discovery-plus2","pt":"flow","to":"233","tot":"num"},{"t":"set","p":"natgeo-plus2","pt":"flow","to":"239","tot":"num"},{"t":"set","p":"viceland-hd","pt":"flow","to":"270","tot":"num"},{"t":"set","p":"worldmovies","pt":"flow","to":"433","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":110,"wires":[[]],"info":"All names are written in lower case.\nChannels like `72` are written as `seven2`\nFox8 are written as `fox8`\nAll `+2` channels are appended with `-plus2`"},{"id":"3b806e2e.f235fa","type":"inject","z":"88de1ac2.8b8c38","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":110,"wires":[["1dd69628.a44192"]]},{"id":"cf0cd74b.0b68","type":"ui_template","z":"88de1ac2.8b8c38","group":"f1fdb5d4.16549","name":"Blank","order":11,"width":"7","height":1,"format":"<div id=\"regular_x\">\n   <md-button class=\"md-button program-names teal\">BLANK\n   </md-button>\n</div>\n\n<script>\n\n(function($scope) {\n\n$('#regular_x').on('click', function(e) {\n    e.preventDefault(); //prevent default behavior\n    $scope.send({\"topic\":\"momentary_regular\",\"payload\": \"abccomedy\"});\n});\n    \n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":330,"y":180,"wires":[["78bf5335.6271f4","945485eb.0bd93"]]},{"id":"78bf5335.6271f4","type":"function","z":"88de1ac2.8b8c38","name":"Magic node","func":"\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":180,"wires":[["39cbf291.a66396"]]},{"id":"945485eb.0bd93","type":"debug","z":"88de1ac2.8b8c38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":440,"y":230,"wires":[]},{"id":"39cbf291.a66396","type":"debug","z":"88de1ac2.8b8c38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":180,"wires":[]},{"id":"f1fdb5d4.16549","type":"ui_group","z":"","name":"Programs","tab":"cead8e37.ba09a","order":1,"disp":true,"width":"8","collapse":false},{"id":"cead8e37.ba09a","type":"ui_tab","z":"","name":"Schedule","icon":"dashboard","order":10,"disabled":false,"hidden":false}]

The button is pressed and abccomedy is sent to the magic node and it finds the association between abccomedy and 152 then spits out the 152 value.

Maybe it would/could be easier if the list was an array. Again: this is just to show the idea.

If that is what would work for you, to pick up the value of "abccomedy" outside of the ui_template when you press the button, you could do like that. You could have such variables in a context object if it makes life easier or you could simply access them individually

But if you need the values already inside the ui_template, like if you want the appearance of the ui to change depending on the values, you have to send them into the ui_template code. You can imagine you would send all such context variables you need in a ui_template when they change, so the ui_template code "always know their state". If you then press the button, it would have access to the "latest". If this hasn't change since that topic was written back in 2018

No, I am thinking of options.

As is, the node sends 152 for (say) abccomedy.

But the channel associations have changed.

So, my thoughts are that rather than sending the actual number of the channel, I send the name.

That then gets sent through a lookup() to find the actual channel number.

Having them in context is an option. I guess I could have them in a file and search the file, but that would require more file I/O and I am not sure that is really needed.

I have no idea of how to do the lookup() in javascript. (Yeah: search/study/learn.)

Just now I am at 300% load, and this will be on going until the other task is completed.
Alas life goes on in the mean time and I am wanting help in how do do this part.

This way the nodes don't need to be changed. It is still channel x and if/when it gets changed again, all I have to do is edit the association table and the number gets sent when the name is sent into the magic node.