## Hl7Segment.setComponent() method [​](/content/docs/sdk/core.hl7segment.setcomponent#hl7segmentsetcomponent-method/index.html)

Sets a component value by field index and component index. This is a shortcut for `getField(field).setComponent(component, value)`. Note that both indices are 1-based, not 0-based.

**Signature:**

```typescript
setComponent(fieldIndex: number, component: number, value: string, subcomponent?: number, repetition?: number): boolean;
```

## Parameters [​](/content/docs/sdk/core.hl7segment.setcomponent#parameters/index.html)

| Parameter   | Type     | Description                              |
|-------------|----------|------------------------------------------|
| fieldIndex  | number   | The HL7 field index                      |
| component    | number   | The component index                      |
| value       | string   | The new component value                  |
| subcomponent | number   | _(Optional)_ Optional subcomponent index |
| repetition   | number   | _(Optional)_ Optional repetition index    |

**Returns:**

boolean

true if the component was set, false otherwise

- [Hl7Segment.setComponent() method](/content/docs/sdk/core.hl7segment.setcomponent#hl7segmentsetcomponent-method/index.html)
- [Parameters](/content/docs/sdk/core.hl7segment.setcomponent#parameters/index.html)
