How to create a Role

#1

This code :
Role.create({id:“SFO_ooiazdnjsks”,name:“SFO”})

returns an error:

all.js?env=browser&compat:19685 POST https://solarlab11.c3-e.com/api/1/solarlab/engietraining11/Role?action=create 500 (Server Error)
C3.client.sendRequest @ all.js?env=browser&compat:19685
request @ all.js?env=browser&compat:885
call @ all.js?env=browser&compat:589
c3Call @ all.js?env=browser&compat:97
_call @ all.js?env=browser&compat:2613
(anonymous) @ VM24154:5
(anonymous) @ VM24247:1
all.js?env=browser&compat:592

Uncaught
C3.client.ActionError
error
:
C3.typesys.Obj
codes
:
Array[1]
debugInfo
:
Array[0]
id
:
"2304.8198"
key
:
“c3.engine.database.DbException_validationErrors"
parameters
:
Array[1]
template
:
”{}"
proto
:
C3.typesys.Obj
message
:
"Write failed: Object with same name already exists in type Role for unique index: C3_2_ADMIN_MEMBER_U_1 for object with id SFO_ooiazdnjsks. Please change to unique values."
name
:
"ActionError"
stack
:
"Error: Write failed: Object with same name already exists in type Role for unique index: C3_2_ADMIN_MEMBER_U_1 for object with id SFO_ooiazdnjsks. Please change to unique values.↵ at new C3.client.ActionError (https://solarlab11.c3-e.com/typesys/1/all.js?env=browser&compat:1154:13)↵ at Object.request (https://solarlab11.c3-e.com/typesys/1/all.js?env=browser&compat:906:15)↵ at Object.call (https://solarlab11.c3-e.com/typesys/1/all.js?env=browser&compat:589:27)↵ at c3Call (https://solarlab11.c3-e.com/typesys/1/all.js?env=browser&compat:97:20)↵ at Object._call (https://solarlab11.c3-e.com/typesys/1/all.js?env=browser&compat:2613:20)↵ at Object.eval (eval at get (https://solarlab11.c3-e.com/typesys/1/all.js?env=browser&compat:2990:20), :5:15)↵ at :1:6"
proto
:
Error

0 Likes

#2

The error you are getting:
"Error: Write failed: Object with same name already exists in type Role for unique index: “
is telling you that the Role already exists. If you want to modify the existing Role you can user Role.upsert().

Note that Role is metadata, and whatever changes you make at runtime will ve overwritten with the next apps provisioning.

So, if you want to persist your Role definition, you must be add it to the corresponding file in the c3apps directory.

0 Likes