Calling an Action on selected products via a Report

  • Updated

The purpose of this Action example is to illustrate how to use the logic from an Action on a user-selected range of Items (in this case Products) by invoking the Action from the Report menu.

This example is provided as inspiration only. It must be adapted to your Perfion environment to work. Perfion Support does not assist with such adaptations. Please contact your Perfion Partner or your Perfion consultant if you need assistance.

The concept needs both a Report (view.xml file) and the Action to call. 

In the superquery the reference to the ID of the Action needs to be written in the <SuperQuery> node. In this case the actionID is "2942", but this must be changed to the ID from your Action.

The <OutputParameters> section is optional, but it illustrates the way to make interaction between the User and the Action. The parameter "ExportPath" is set in the Report dialogue and is available as a variable in the Action.

Report SuperQuery

<SuperQuery actionID='2942' >
  <Query>
    <Select languages='EN' view='Normal'>
      <Feature id='Image' />
    </Select>
    <From id='100'/>
    <Where>
      <Clause id='Image' operator='HAS' />
    </Where>
  </Query>
  <OutputParameters>
    <Parameter id='ExportPath' input='Perfion.LookUp.DirectoryPath' />
  </OutputParameters>
</SuperQuery>

Action Map

  • All lines containing a Command are created as virtuals. This is a recommended best practice

Sample data for building Action Map

Data must be adapted to your Perfion environment to work

Action Map - FromToCommandScriptNote
RowtblFixedSELECT The input DataTable from the Report must be called "Row"
i__IDID   
i__NameCleanItemNumber 

string inputString = Trim( Value );

string cleanString = System.Text.RegularExpressions.Regex.Replace(inputString, @"[^a-zA-Z0-9\-]", "");

Value = cleanString;

This C# script removes any illegal characters from  the Name.
i_ImageImage   
tblFixedtblFilesSELECT  
IDID   
{CleanItemNumber}-{ID}-productimageFilename  Note the curly bracket syntax in the From column.
This notification form combines different variables and makes one value
ImageImage   
tblFiles SELECT  
ID    
FilenameFileName   
ImageImage 

if( !HasValue ) return;

string ExportPath = "";

var lookupParam = Sources.SelectFirst( "Parameters", "" );
if( lookupParam != null ) {
ExportPath = ""+lookupParam["ExportPath"];
}

string id = Path.GetFileNameWithoutExtension( ""+Value );

var info = Perfion.WriteFile(
id:id,
file:"{FileName}",
par:"size=300x300&format=jpg",
root:ExportPath
);

Value = info.OutFileName;

This C# script writes the Product Images to physical files.
The location of the images is set from the variable "ExportPath", which is set by the user in the report dialogue.

 

The script also writes the images from the feature called "Image" from the selected products.

It uses the Perfion script method "WriteFile" with customized parameters.

Please refer to the documentation for details on using this method.

 

 

The written filename are set to the output Value for reference if needed later even though the value is not actually used in this example.

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.