Hello Pierre,

You have two options to get query parameters

  1. You can merge the entire %request.Data into local array and use string function.
  2. User %request.Next(data) method to loop the %request.Data one by one and get query parameter values

ClassMethod GetQueryParams()
{
	set data=""
	For {
		set data  = %request.Next(data) quit:data=""
		write data,!
	}
}
OUTPUT
Bottom
Name
Top

For cgiEnvs. You can follow same merge option to get all values. Otherwise use  %request.NextCgiEnv(cgi) to get the list of available values.

ClassMethod GetcgiEnvs()
{
    set cgi=""
    for {
        set cgi  = %request.NextCgiEnv(cgi) quit:cgi=""
        write cgi,!
    }
}

Hello @ARTHUR L A SILVA 

You create a your custom task and schedule this task in task manager if it's required. Follow the below steps to schedule the task.

  1. Create a new class definition with extends of %SYS.Task.Definition. Override the OnTask() method and necessary logic inside the method
  2. Goto System Management portal > System Operation>Task Manager>NewTask
    1. Add unique task name
    2. Select namespace
    3. Assign the task type ( which is your class definition)
    4. Select output file when task running
    5. Provide your ouputfile.csv in the output file
    6. schedule the execution date and time.
    7. Finish the task
Class Samples.TaskMgr.SQLExportTask Extends %SYS.Task.Definition
{

Parameter TaskName As STRING = "ExportQueryToCSV";

Method OnTask() As %Status
{
    set statement = ##class(%SQL.Statement).%New()
    /// Place your sql query
    set sql = "Select Name,dob,Phone From Samples_DB.Person"
    set tSC = statement.%Prepare(sql)
    if $$$ISERR(tSC) Q $$$OK
    set result = statement.%Execute()
    #dim meta As %SQL.StatementMetadata= result.%GetMetadata()
    for i=1:1:meta.columnCount {
        if i>1 w ","
        write meta.columns.GetAt(i).colName
    }
    write $$$NL
    while result.%Next()
    {
        write result.Name,",",result.dob,",",result.Phone,$$$NL
    }
    return $$$OK
}
}

Task scheduler

 

Hi @Sakthivel Perumal 

Can you try the below sample to download file from the directory

Class Samples.CSPFileDownload Extends %CSP.Page
{
Parameter CONTENTTYPE As STRING = "application/text";
ClassMethod OnPage() As %Status
{
    do %stream.OutputToDevice()
    return $$$OK
}
ClassMethod OnPreHTTP() As %Boolean
{
    #; your directory and file
    set file="C:\Users\readmyfile.txt" 
    set stream=##class(%Stream.FileCharacter).%New()
    set sc=stream.LinkToFile(file)
    set %stream = stream
    set %response.ContentType = ..#CONTENTTYPE
    set %fileName = file
    set %response.ContentLength=stream.Size
    return $$$OK
}
}

Hello @Elijah Cotterrell 

Thanks for the suggestion, I need to verify whether the property is modified while saving for opened object and Generally I do some verification with the mentioned piece of code. So, I thought to generate a method like getter and setter method in some cases.

Class Samples.Person Extends %Persistent
{

Property Name As %String;

Property Age As %String;
ClassMethod ValidateObject()
{
    Set obj =##Class(Sample.Person).%OpenId(1)
    w "before: ",obj.PropertyIsModified("Age"),!
    Set obj.Age=12
    Write "after: ",obj.PropertyIsModified("Age"),!
}

Method PropertyIsModified(Property)
{
    Return $Select(Property'="":$Property($THIS,"m%"_Property), 1:0)
}

}

Thanks Vitaliy for the suggestion, %ScrollableResultSet  is works for the Cache SQL. We are actually fetching multiple Resultsets and not working as expected for language=tsql.

ClassMethod tt() [ Language = tsql, SqlName = mycls, SqlProc ]
{
    SELECT Name FROM sample_SQL.NewClass4
    SELECT Name, Age FROM sample_SQL.NewClass5
}

 set results=##class(%ScrollableResultSet).%New()
 set tsc = results.Prepare("call sample_SQL.MYCLS()")
 if $$$ISERR(tsc) W $SYSTEM.OBJ.DisplayError(tsc)
 do results.Execute()
 
 ERROR #6048: Invalid Statement Type: 'CALL'1

If you're receiving unexpected fields(key value pairs) as part of the JSON and the properties are not included in the class definition. You need to add the below parameter in your class definition(%JSON.Adaptor extended class). This will ignore loading the unexpected field.

Parameter %JSONIGNOREINVALIDFIELD As BOOLEAN = 1

In addition, The JSON key-value pair data type should match with class definition property datatype.