Question Raja Seetharaman · Aug 18, 2024

How to programmatically update a port number on multiple items.

Hello, I am total newbie when it comes to ObjectScript (just started going through the tutorial).  We have a task where we have to update the port number for 75-100 items (say for half of the items in our production).  Going through the documentation and other community posts it looks like we could utilize class method 'ApplySettings' in Ens.Production.  But we are running into an issue.  Below is what we currently have.  When we hard code the item, it works.  But, if we store the item in a variable and try it pass it through.  Then it doesn't work.  We are also not seeing an error.  Is our thought process valid or should be looking at it differently.  Can we pass a variable into pSettings list?  If so, how should our syntax be?

Step 1: Got a list of items by running a sql against Ens_Config.item to get the name and added to a file. (Each item is in a line by itself)

Step 2: Trying to run the class method below to read the file and loop through the values to update port number.

ClassMethod UpdatePort() As %String
{
set tUniqueFile = "/hs-connect/test/Jobs_To_Update.txt"
// Write the file from previous line to a stream
set tStream = ##class(%Library.FileCharacterStream).%New()
Set tSC=##class(Ens.Util.File).LinkFileStream(tUniqueFile,.tStream)
set tStream.Filename = tUniqueFile // Read the stream to gather the job values
if $$$ISERR(tSC) quit ;
    while 'tStream.AtEnd {
        set str=tStream.ReadLine()
        write !,"The Job Is: ",str
        
        //set pSettings("From_Source_Rec_Job","Adapter","FTPPort")=2022.  If we specify the job, then it works
        set pSettings(""_str_""),"Adapter","FTPPort")=2022  //If we try to pass the variable, it does not
do ##class(Ens.Production).ApplySettings("TST.Production", .pSettings)                
}
// Delete the file with the list of jobs
do ##class(%Library.File).Delete(tUniqueFile) write !
return tSC
}

Regards,

Raja

Comments

Robert Cemper · Aug 18, 2024

with   set pSettings("From_Source_Rec_Job","Adapter...

you pass a String literal

assuming the value of your variable  str = From_Source_Rec_Job

then    set pSettings(str,"Adapter","FTPPort")=2022 

should be sufficient

0
Raja Seetharaman · Aug 19, 2024

HI Robert, thank you very much.  Along with the change you suggested, I also had to update the delimiter of the input file.  Since the file was created in Windows, it had <CR><LF>.  We had to update it to just <LF> since our instance runs on Linux.  After the changes it works perfectly.  Thank you again for your help.

Regards,

Raja

0