Renaming part of title attachment
I need to assign the rename function to the button "Manuell Nr zuweisen". By clicking on it, an alert field should come out in which you are asked to enter the number you want with a blank field to digit it.
With this action I should rename the first numerical part of the title of the attached file.
The field "Internet Nr." extrapolate the number automatically with this formula:
extractx(Titel, "-[^0-9]*(\d+)[^1-9]*(\d+,?\d*)x[^1-9]*(\d+,?\d*)cm-[^1-9]+(\d+)-?(\d+)?", "", "$1 ")
So the value that I need to rename is "$1" and it is present in the field "Titel.
I used this formula to see the name of the attachment in that field:
extractx(text(Vorschau), "(.+)\/(.+)", "i", "$2")
I know that I can rename that part of the file manually with the "rename" function of the attached file. The problem is that I have colleagues who don't understand it with the risk of causing trouble
Thanks for all your help
19 replies
-
You have two options :
1 - Use html in a formula :
"set the file to rename here"; var file := first(files(this)); "set the new file name here"; var newFileName := "test.jpg"; var uniqId := "btn" + now(); html(" <div id='" + uniqId + "' classe='component' title='' onclick='renameFile()' style='width:100%;padding:0px;text-align: center; -moz-user-select: none;-webkit-user-select: none;-ms-user-select: none;user-select: none;'> <div class='nx-button-text blue'>Run code</div> </div> <script> // code to setup the button var me = document.getElementById('" + uniqId + "'); me.closest('.html').style = 'padding:0px;height:34px'; me.closest('.stringeditor').style = 'border-width: 0px;' var label = me.closest('.editor-html').querySelector('label') me.querySelector('.nx-button-text').innerText = label.innerText; label.style.display = 'none'; // function to rename file function renameFile() { var f = util.parseNIDFile('" + file + "'); database.renameFile(f[0] + f[1], f[2], '" + newFileName + "', (err) => { if (err) alert(err); }); } </script>")
This formula creates a button similar to those of Ninox and calls the renameFile function when you click on it.
2 - Uses NativeJS :
Put this code on button formula.
"set the file to rename here"; var file := first(files(this)); "set the new file name here"; var newFileName := "test2.jpg"; #{ var f = util.parseNIDFile(file); database.renameFile(f[0]+f[1], f[2], newFileName, (err) => {if (err) alert(err);}); }#
-
Thank you Jacques TUR
I was searching a way to give the permission to edit only the value "$1" of the title, that means only the first numeric value. I can't put a default new name for the file because it's different for each one. So eventually, Ninox has to ask me to insert the new filename with an alert and an empty field.
A second possibility could be to make a button-formula that will give the permission to edit manually the field "Interne Nr" that is actually extracting the number $1 from the title.
That means that with a button you can overwrite the extracted value with the number you will digit in the alert field
-
thomas said:
Unfortunately it gives me an error. I guess it could be because the content of the "title" field is generated by a formulaThat is your problem. You can not modify a formula field by forcing a value into it.
You have to two options:
1) Since “title” is a formula field, You can replace the number in the number or text field that makes up the part of the name that you need to change.
or
2) You can write the results to a new field.
-
What if I'm going to edit the formula of the field where the number from the title is extracted and put there an if else function?
Something like that:
if 'Nr zuweisen' = null then extractx(Titel, "-[^0-9]*(\d+)[^1-9]*(\d+,?\d*)x[^1-9]*(\d+,?\d*)cm-[^1-9]+(\d+)-?(\d+)?", "", "$1 ") else 'Nr zuweisen'
I've tried it and if there is no number in the field "Nr zuweisen" there is no problem.
As soon as I enter a number, the internal number field remains empty. I would like it to copy the number entered in the "Nr. zuweisen" field if present and greater than 0, otherwise it should execute the extractx formula to extract the number from the title.
I think this solution might work as workaround but maybe I'm doing something wrong in the if else formula
-
You are close. Can you give me the code for the formula for the Titel field?
-
Looking at the starting post, you have the field 'Interne Nr.' Is that a user editable field? If not then you can try the following in your Titel formula:
let x := if 'Nr zuweisen' = null then 'Interne Nr.' else 'Nr zuweisen' end; field1 + "-" + "Nr"+ x + etc...
Here we create variable that checks if 'Nr zuwisen' is empty and if it is then it will use the value in 'Interne Nr.' else it will use the value in 'Nr zuwisen'.
Then we use that variable in the formula that creates the Titel.
-
I don't understand why this doesn't work
Your formula and my doesn't work
Error on line 5 for both formula is:
The expressions "then" and "or" provide different types of values: string, number in line 5, column 3
-
Sorry this is taking so long. Thanks for putting up with my silly questions that you have already answered in your original post.
I think I know a solution. You have two formula fields (Titel, Interne Nr.). Which means you need a new text field if you want to change Titel with what is in Nr zuweisen.
In the button you can try something like:
'new text field := if 'Nr zuweisen' = null then Titel else replace(Titel,'Interne Nr.','Nr zuweisen') end
Or you can put the formula into a new formula field (without the ‘new text field’ part) and the end user doesn’t have to press a button.
Content aside
- Status Answered
- 1 yr agoLast active
- 19Replies
- 334Views
-
3
Following