Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By clintjb
#794051
Hi All,
Ive been struggling today with what Im assuming should be a very simple excercise. Basically I have two variables called "cost" and "price" that are fed by previous process steps.

I have a 3rd variable called "margin" that I would like to be automatically calulcated as a percentage of the first two. I assumed at least to get it as a number would be as simple as selecting the text field linked with margin and editing the formula field to something like:
Price / Cost - 100%
or
@@Price / @@Cost
This however doesnt seem to work... Does anyone have any suggestions? Currently Im doing it as JS but it seems like not the best solution.

Secondly (and now Im certain much more complicated) I would like to export a CSV file of this particular instance only. By that I mean a CSV with exactly these three values only and not an extract of the complete DB. Is this at all possible? I only saw documentation linking to complete reports.

Thanks in advanced,
By clintjb
#794065
Hi All,
So I found solutions to both problems and thought I would share in case anybody else has similar issues....

I had the display mode set to "view" which was causing it not to calculate - resetting it back to parent and it works like clockwork.

Secondly regarding the CSV Ive added the following code to the page which has also solved my issue
Code: Select all
var PN = parseInt($("#Number").getValue())
var Cost = parseInt($("#Cost").getValue())
var Price = parseInt($("#Price").getValue())
// The data to put in CSV
var data = [
  ['#Part_Number', '#Cost', '#Price'],
  [PN, Cost, Price],
];

// Loop through the data array and build the csv file to be downloaded
// Each column is seperated by ";" and new line "\n" for next row
var csvContent = '';
data.forEach(function(infoArray, index) {
  dataString = infoArray.join(';');
  csvContent += index < data.length ? dataString + '\n' : dataString;
});

// Content is the csv generated string above
var download = function(content, fileName, mimeType) {
  var a = document.createElement('a');
  mimeType = mimeType || 'application/octet-stream';

  if (navigator.msSaveBlob) { // IE10
    navigator.msSaveBlob(new Blob([content], {
      type: mimeType
    }), fileName);
  } else if (URL && 'download' in a) { //html5 A[download]
    a.href = URL.createObjectURL(new Blob([content], {
      type: mimeType
    }));
    a.setAttribute('download', fileName);
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
  } else {
    location.href = 'data:application/octet-stream,' + encodeURIComponent(content); // only this mime type is supported
  }
}

download(csvContent, 'upload_IMS.csv', 'text/csv;encoding:utf-8');
Hopefully this helps someone else out.
Cheers

Being the best in the started business is the obje[…]

Winzo is a popular and unique game on the mobile p[…]

Cannot create process using templets

Real details. The problem was solved by effect!

However, it is essential to use it responsibly and[…]