워크플로우 매개변수를 멤버로 포함하는 객체를 매개변수로 사용하는 validate 멤버를 추가하여 워크플로우에서 입력을 검증할 수도 있습니다. validate 함수는 각 멤버의 이름이 검증에 실패한 매개변수로 지정되었으며 각 멤버의 값이 사용자에게 표시될 검증 실패 메시지인 객체를 반환해야 합니다.
예 23 워크플로우 입력 검증다음과 같이 예제를 확장하여 사용자가 이미 있는 공유를 만들려고 하는 경우 명확한 오류를 제공할 수 있습니다.
var workflow = { name: 'Create share', description: 'Creates a new share in a business unit', parameters: { name: { label: 'Name of new share', type: 'String' }, unit: { label: 'Business unit', type: 'ChooseOne', options: [ 'development', 'finance', 'qa', 'sales' ], optionlabels: [ 'Development', 'Finance', 'Quality Assurance', 'Sales/Administrative' ], } }, validate: function (params) { try { run('shares select ' + params.unit); run('select ' + params.name); } catch (err) { if (err.code == EAKSH_ENTITY_BADSELECT) return; } return ({ name: 'share already exists' }); }, execute: function (params) { try { run('shares select ' + params.unit); } catch (err) { if (err.code != EAKSH_ENTITY_BADSELECT) throw (err); /* * We haven't yet created a project that corresponds to * this business unit; create it now. */ run('shares project ' + params.unit); set('mountpoint', '/export/' + params.unit); run('commit'); run('shares select ' + params.unit); } run('filesystem ' + params.name); run('commit'); return ('Created new share "' + params.name + '"'); } };