Hi @ashrafsam
I did a bunch of reading and finally got into the Open ai help bot on the AP help pages. Here’s what I came up with…do you think any of this is helpful advice?
My Question - Please write the appropriate code to paste into the Code Piece to replace three example words with three example replacement words
Certainly, in the Code Piece, the task to replace words can be accomplished in JavaScript using the replace()
function. Below is the code for replacing three example words, ‘word1’, ‘word2’, and ‘word3’, with the replacement words ‘replacement1’, ‘replacement2’, and ‘replacement3’, respectively:
function main({inputs}) {
let text = inputs.text;
const replacements = {
'word1': 'replacement1',
'word2': 'replacement2',
'word3': 'replacement3'
};
for (let word in replacements) {
let replacement = replacements[word];
text = text.replace(new RegExp(word, 'g'), replacement);
}
return {
text: text
};
}
In this example, the inputs
argument is a JavaScript object with a property text
, which is the string that you want to transform. The replacements
object maps the original words to their replacements. The for...in
loop iterates over the properties (i.e., words to replace) in the replacements
object.
Finally, for each word to be replaced, the code uses the replace
method to replace all occurrences of the word (designated by the ‘g’ flag in RegExp(word, 'g')
) with its replacement.
To use this in Activepieces, you need to paste this code into the ‘Code’ section of the Code Piece. Then, in the Parameters section, add a parameter named ‘text’ and input the text in which you want to replace words.
I tried my best to insert the code, add parameters, etc etc for hours. I just kept failing. Any ideas?
TimMan