cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Generate an ID number in SAP Build Process Automation

ElyasD
Explorer
1,149

Hello,

 

I am creating a process automation form in SAP Build Process Automation. I am trying to configure the form to generate an auto-generated sequential ID number and send it by email to the approver.

I used the script option, but it does not seem to be working.

Do you have any guidelines on how to achieve this?

ElyasD_0-1736429536337.png

 

Accepted Solutions (0)

Answers (2)

Answers (2)

arroyoweisson
Participant

Hi @ElyasD ,

Agree with @Dinu , there is no way you can achieve this via custom scripting. You can generate a randomize ID number. 

Something like this:

Function generateUniqueRandomNumberString(length) {
    const timestamp = Date.now().toString();
    let randomPart = '';
    const characters = '0123456789';
    const charactersLength = characters.length;
    for (let i = 0; i < length - timestamp.length; i++) {
        randomPart += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    return timestamp + randomPart;
}

// Example
const uniqueRandomNumberString = generateUniqueRandomNumberString(20);
console.log(uniqueRandomNumberString);

What I have implemented on my project was. The generated ID was saved somewhere (S4 Table, Database,Excel). The automation has to get the last ID# in able to add the corresponding sequence.

Regards,

 

weisson

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Likes
OK, but that was not a script used in Process Automation Script Task, was it?
ElyasD
Explorer
0 Likes

Hi @Dinu
I did a very simple scripting just to generate the code. But unfortunately, it did not work. 

 

function generateUniqueID() {
    var uniqueID = new Date().getTime().toString() + Math.random().toString(36).substring(2, 10);
    return uniqueID;
}

generateUniqueID();
 
 
Thank @arroyoweisson for the answer. 
gultekin
Newcomer
0 Likes
between
Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Likes

The Script Task has some constraints, described here: https://help.sap.com/docs/build-process-automation/sap-build-process-automation/restrictions-on-scri...

One of them is no Functions, so that script will not work.

The following script worked for me, modified from @arroyoweisson's script.

var length = 15;
var timestamp = Date.now().toString();
var randomPart = '';
var characters = '0123456789';
var charactersLength = characters.length;
var i;
for (i = 0; i < length - timestamp.length; i++) {
	randomPart += characters.charAt(Math.floor(Math.random() * charactersLength));
}
$.context.custom.mynumber = timestamp + randomPart;

 I created a custom variable called "mynumber", to which I return the number (instead of using return).

For your simpler one (though you get characters because of radix 36):

var uniqueID = new Date().getTime().toString() + Math.random().toString(36).substring(2, 10);
$.context.custom.mynumber = uniqueID;

HTH

P.S.: I don't see how this will get you a sequence number, though it will give you numbers going higher.

 

😺

ayechan
Participant
0 Likes

Hi @ElyasD,

I have same requirement as your requirement.

And firstly, I would like to apologize for asking another question instead of answering your question.

If you don't mind, could you please answer for me?

 

For mail sending step, what kind of mail type (eg. gmail, outlook) do you use.

In my case, I would like to use outlook mail, but the following error is keep occurring.

ayechan_1-1741757689422.png

So, if you use outlook mail setting and possible to create without any issue, could you please share with me how to create mail setting for outlook mail type?

Best Regards,

Aye Chan