Batch run of methods


#1

To do batch update or creation of data I try to run the following code:
for (var i = 0; i < this.SelectedParams.length; i++){
this.NewFamParam = {
"parent_id":null,
"family_revision_id":this.parameters.FamRevId,
"spf_content_id":this.SelectedParams[i].spf_cont_id,
"description":this.SelectedParams[i].description_en,
"formula_id":null,
"is_instance":true,
"order":i+1,
"phase_id":null
}
this.lhpg.createFamilyParameter(this.NewFamParam).subscribe(
(result: any) => {this.notificationService.notify({ severity: "success", summary: Success, detail: Parameter was added });},
(result: any) => {this.notificationService.notify({ severity: "error", summary: Error, detail: Unable to create new FamilyParameter! });});
}

But the compiler complains about the subscribe() method. If I put this code later in .ts file - everything runs as expected. Is it a bug?


#2

I don't understand what the problem is.

But the compiler complains about the subscribe() method

What is the error message?

If I put this code later in .ts file - everything runs as expected

What do you mean?


#3

What I need is a notification message at each step, so I see which of steps are successful. If I edit the resulting .ts file the application runs and built exactly with this functionality. But Radzed doesn't allow me to insert it in the original code.


#4

The code you are using isn't valid TypeScript. Try this one:

for (var i = 0; i < this.SelectedParams.length; i++){
    this.NewFamParam = {
        "parent_id": null,
        "family_revision_id": this.parameters.FamRevId,
        "spf_content_id": this.SelectedParams[i].spf_cont_id,
        "description": this.SelectedParams[i].description_en,
        "formula_id": null,
        "is_instance": true,
        "order": i + 1,
        "phase_id": null
    };

    this.lhpg.createFamilyParameter(this.NewFamParam).subscribe(
        (result: any) => {
            this.notificationService.notify({ severity: "success", summary: `Success`, detail: `Parameter was added` });
        },
        (result: any) => {
            this.notificationService.notify({ severity: "error", summary: `Error`, detail: `Unable to create new FamilyParameter!` });
        }
    );
}

#5

The same. "Unexpected identifier"


#6

You can load the project in Visual Studio (Professional or Code) and see what exactly the TypeScript error is.


#7

VS does not show any error and the application compiles and works as expected. This is what I meant in my first message.


#8

I didn't understand this is what you meant. Where is this code entered in Radzen? What kind of action is that - Set property, Execute Code? You can paste a screenshot from the event editor so we can check it further.


#9

I use it in a button event to run batch process:


#10

Got it. It seems to be using `` that breaks our internal parser. You can use " as a workaround:

OLD:

    this.lhpg.createFamilyParameter(this.NewFamParam).subscribe(
        (result: any) => {
            this.notificationService.notify({
             severity: "success", 
             summary: `Success`, 
             detail: `Parameter was added` 
          });
        },
        (result: any) => {
            this.notificationService.notify({ 
               severity: "error", 
               summary: `Error`, 
               detail: `Unable to create new FamilyParameter!` 
           });
        }
    );

NEW:

 this.lhpg.createFamilyParameter(this.NewFamParam).subscribe(
        (result: any) => {
            this.notificationService.notify({
             severity: "success", 
             summary: "Success", 
             detail: "Parameter was added"
          });
        },
        (result: any) => {
            this.notificationService.notify({ 
               severity: "error", 
               summary: "Error", 
               detail: "Unable to create new FamilyParameter!" 
           });
        }
    );

#11

Yep, now it works, thank you.


#12

We will fix that with the next release.


#13

Radzen 2.10.1 just released with fix for this included!